DEV Community

Discussion on: Go's method is curried funtion

Collapse
 
mattn profile image
Yasuhiro Matsumoto • Edited

Yes, in strictly, as you think, this is not currying. The currrying is a transform taking one less argument.

package main

import (
    "fmt"
)

func add(n int) func(int) int {
    return func(v int) int {
        return n + v
    }
}

func main() {
    add10 := add(10)
    fmt.Println(add10(5))
}

Just metaphor :)

If this function object for currying, you can try this.

package main

import (
    "fmt"
)

type number int

func (f number) add(b number) number {
    return f + b
}

func main() {
    fmt.Println(number(3).add(4))
    fmt.Println(number.add(3, 4))
}