Documentation
¶
Overview ¶
Package curry provides function currying for go.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Curry ¶
func Curry(f interface{}) interface{}
Curry takes a function and allows it to be called lazily until the arguments are all populated. The curried functions take arbitrary arguments instead of just one so that lazy population can occur in steps larger than one. This change from normal currying is simply a conveinence.
Example (AllArgsAtOnce) ¶
curriedAdd := Curry(func(x, y, z int) int { return x + y + z }) out := dyn.Apply(curriedAdd, 1, 2, 4) fmt.Println(out)
Output: 7
Example (IsFunc) ¶
curriedAdd := Curry(func(x, y, z int, rest ...int) int { out := x + y + z for _, e := range rest { out += e } return out }) fmt.Printf("%T\n", curriedAdd)
Output: func(...interface {}) interface {}
Example (ThreeArgs) ¶
curriedAdd := Curry(func(x, y, z int) int { return x + y + z }) add1 := dyn.Apply(curriedAdd, 1) add3 := dyn.Apply(add1, 2) out := dyn.Apply(add3, 4) fmt.Println(out)
Output: 7
Example (ThreeArgsSecondTwoAtOnce) ¶
curriedAdd := Curry(func(x, y, z int) int { return x + y + z }) add1 := dyn.Apply(curriedAdd, 1) out := dyn.Apply(add1, 2, 4) fmt.Println(out)
Output: 7
Example (ThreeArgsTwoAtOnce) ¶
curriedAdd := Curry(func(x, y, z int) int { return x + y + z }) add3 := dyn.Apply(curriedAdd, 1, 2) out := dyn.Apply(add3, 4) fmt.Println(out)
Output: 7
Example (TwoArgs) ¶
curriedAdd := Curry(func(x, y int) int { return x + y }) add1 := dyn.Apply(curriedAdd, 1) out := dyn.Apply(add1, 2) fmt.Println(out)
Output: 3
Example (Variadic) ¶
curriedAdd := Curry(func(x, y, z int, rest ...int) int { out := x + y + z for _, e := range rest { out += e } return out }) out := dyn.Apply(curriedAdd, 1, 2, 3, 4, 5) fmt.Println(out)
Output: 15
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.