curry

package module
v0.0.0-...-26cbaf2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 3 Imported by: 0

README

Curry

GoDoc Build Status

This package provides arbitrary function currying for go programs.

Getting started

go get jsouthworth.net/go/curry

Usage

The full documentation is available at jsouthworth.net/go/curry

License

This project is licensed under the MIT License - see LICENSE

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL