A lightweight Go library that brings the power of function currying to your codebase.
Currying is a functional programming technique where a function with multiple arguments is transformed into a sequence of functions, each taking a single argument.
Example:
// Regular function
func add(a, b int) int {
return a + b
}
// Curried version
func add(a int) func(int) int {
return func(b int) int {
return a + b
}
}
addTwo := add(2)
result := addTwo(3) // result is 5This approach allows for more flexible and reusable code, enabling partial application of functions.
- Currying Functions: Transform standard Go functions into their curried counterparts.
- Uncurrying Functions: Revert curried functions back to their original form.
- Partial Application: Create new functions by pre-filling some arguments.
- Return Values Dropping: Ignore first or last function return values.
- Lazy Arguments Evaluation: Convert function parameters to thunk functions.
- Tail: Pop an element and get the tail of a sequence.
- Take N: Cut a sequence after pulling first N elements.
- Filter: Filter sequence values.
- Map: Convert sequence values.
- Until: Pull values until condition is true.
- Last: Consume the sequence and return the last value.
- Accumulate: Compute an accumulated value.
- Zip: Join two sequences to a sequence of pairs.
- Range: Generate integers in a range, with a given step.
- Generate: Generate a sequence of a function return values.
- Channels: Convert a sequence to a channel, or the other way around.
go get github.com/parametalol/currySee examples for usages.
Contributions are welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License.