# How to Write a Nested Recursive Function in Golang

The other day, I was solving a leetcode question. I was using Python, but somehow, I can not pass the OA, although it ran pretty fine in “run code against your own input”. Long story short: I decided to use Go to write the solution. While trying to write a helper function (a nested recursive function), I found some interesting things about functions in Go, which I think are worth sharing. Function type, value, literal, closure and scope in Go

## Motivation

The other day, I was solving a leetcode question. I was using Python, but somehow, I can not pass the OA, although it ran pretty fine in “run code against your own input”.

Long story short: I decided to use Go to write the solution. While trying to write a helper function (a nested recursive function), I found some interesting things about functions in Go, which I think are worth sharing.

## Write a nested recursive sum

To ignore the needless complex logic, I will use `sum` function in this article instead of the original one. It takes a single argument `k` , return the sum from natural number `k` to `1`. For instance, `sum(3)` should be `6` , since`3 + 2 + 1` equals to `6` .

Anyway, here is the pattern: a global function called `sum` , in which a `helper` function is defined, which will invoke it self to produce the result recursively. The `sum` function invokes `helper` to start the recursion.

## Golang Receiver Function Example | Go Function Receivers

Golang Receiver Function Example | Go Function Receivers. You can set a method on the new typed variable, and that method is Receiver function.

## How to Make Pure Functions (Go)

Pure functions are often hyped up in the JavaScript world, probably because of the abundance of stateful front end applications. While pure functions have their downsides (i.e. inconvenience, potentially large argument lists), they should be used as much as reasonably possible.

## Functional Programming

Functional Programming: Functional Programming is a Declarative style of Programming Paradigm for writing computer programs.

## Are functions from programming really functions?

Are functions from programming really functions? If you are reading this, then most probably you already know quite well what functions are in programming.

## Simplifying Functional Programming with Recursion (Javascript)

Recursion is a lot less complicated than you might think! Don’t believe me?? Read on! In this article, we’ll breakdown recursion by walking through three examples — then dive into the benefit and uses of recursion.