Quark.Curry (Quark v2.3.2) View Source

Currying breaks up a function into a series of unary functions that apply their arguments to some inner n-ary function. This is a convenient way to achieve a general and flexible partial application on any curried function.

Link to this section Summary

Functions

Curry a function at runtime, rather than upon definition

Define a curried function

Define a curried private function

Convert a curried function to a function on pairs

Apply one or more arguments to a curried function

Link to this section Functions

Specs

curry((... -> any())) :: (... -> any())

Curry a function at runtime, rather than upon definition

Examples

iex> curried_reduce_3 = curry &Enum.reduce/3
...> {_, arity} = :erlang.fun_info(curried_reduce_3, :arity)
...> arity
1

iex> curried_reduce_3 = curry &Enum.reduce/3
...> curried_reduce_3.([1,2,3]).(42).(&(&1 + &2))
48
Link to this macro

defcurry(head, list)

View Source (macro)

Define a curried function

Link to this macro

defcurryp(head, list)

View Source (macro)

Define a curried private function

Specs

uncurry((any() -> (... -> any()))) :: (any(), any() -> any())

Convert a curried function to a function on pairs

Examples

iex> curried_add = fn x -> (fn y -> x + y end) end
iex> add = uncurry curried_add
iex> add.(1,2)
3

Specs

uncurry((... -> any()), any() | [any()]) :: any()

Apply one or more arguments to a curried function

Examples

iex> curried_add = fn x -> (fn y -> x + y end) end
...> uncurry(curried_add, [1,2])
3

iex> add_one = &(&1 + 1)
...> uncurry(add_one, 1)
2

iex> curried_add = fn x -> (fn y -> x + y end) end
...> add_one = uncurry(curried_add, 1)
...> add_one.(3)
4