lumiluminousai / golang-fp-utility

This Go package is crafted to help developers embrace functional programming paradigms in Go. With a suite of utility functions, this package encourages immutable coding practices, helping you move away from traditional mutable loops like for loops. Together
GNU Lesser General Public License v3.0
0 stars 2 forks source link

need Curry function, Currying transforms a function that takes multiple arguments into a series of functions #32

Closed lumiluminousai closed 2 months ago

lumiluminousai commented 2 months ago

func Curry[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R

Description: Currying transforms a function that takes multiple arguments into a series of functions, each taking a single argument. This is useful for partial application, where you can supply some arguments now and others later.

Why: Currying allows functions to be partially applied, which can simplify code reuse and readability.

example: add := func(a int, b int) int { return a + b } curriedAdd := Curry(add) addFive := curriedAdd(5) result := addFive(10) // result = 15