Closures, Factories, and Currying in Go

package main

import "fmt"

func multiply(x, y int) int { return x * y }

func double(x int) int { return multiply(x, 2) }

func main() {
    fmt.Println(double(5))

    triple := makeMultipier(3)

    fmt.Println(triple(5))

    increment := counter()

    fmt.Println(increment()) // 1
    fmt.Println(increment()) // 2
    fmt.Println(increment()) // 3
    fmt.Println(increment()) // 4
    fmt.Println(increment()) // 5
}

func makeMultipier(m int) func(x int) int {
    return func(x int) int {
        return x * m
    }
}

func counter() func() int {
    count := 0
    return func() int {
        count++
        return count
    }
}