Curry (Curry Elixir v1.0.0)
A simple module to do currying and partial application using Variadic functions to start partial evaluation (i.e. no lists needed).
currying-example
Currying example:
iex> import Curry
iex> curry_fun = curry(&Curry.test3/3)
#Function<0.51120925/1 in Curry.curry/1>
iex> next_fun = curry_fun.(1)
#Function<1.51120925/1 in Curry.do_generate_next/3>
iex> next_fun = next_fun.(77)
#Function<1.51120925/1 in Curry.do_generate_next/3>
iex)> next_fun_or_result = next_fun.(10)
{88, {1, 77, 10}}
iex> info(curry_fun)
[
function: &Curry.test3/3,
type: "Currying",
function_arity: 3,
args_still_needed: 3,
args_collected: 0
]
partial-application-example
Partial application example:
iex> partial_fun = partial(&Curry.test5/5, 1, 2)
#Function<19.126501267/3 in :erl_eval.expr/5>
iex> info(partial_fun)
[
function: &Curry.test5/5,
type: "Partial application",
function_arity: 5,
args_still_needed: 3,
args_collected: 2
]
iex> partial_fun.(3, 4, 5)
{15, {1, 2, 3, 4, 5}}
Link to this section Summary
Functions
Does currying of the supplied function (capture)
Generates the next lambda or the result
Gets information about the lambda/fn
Does partial application
Link to this section Functions
Link to this function
curry(fun)
Does currying of the supplied function (capture)
example
Example:
iex> curry_fun = curry(&Curry.test3/3)
#Function<0.82106290/1 in Curry.curry/1>
iex> curry_fun.(1).(2).(3)
{6, {1, 2, 3}}
example-1
Example:
iex> curry_fun = Curry.~>(&Curry.test3/3)
#Function<0.82106290/1 in Curry.curry/1>
iex> last = curry_fun.(1).(2)
#Function<1.82106290/1 in Curry.do_generate_next/3>
iex> last.(3)
{6, {1, 2, 3}}
Link to this function
do_generate_next(fun, args, type)
Generates the next lambda or the result
Link to this function
info(fun)
Gets information about the lambda/fn
example
Example:
iex> Curry.info(partial_fun)
[
function: &Curry.test5/5,
type: "Partial application",
function_arity: 5,
args_still_needed: 3,
args_collected: 2
]
Link to this function
partial(args)
Does partial application
example
Example:
iex> partial_fun = Curry.partial(&Curry.test5/5, 1, 2)
#Function<19.126501267/3 in :erl_eval.expr/5>
iex> partial_fun.(3, 4, 5)
{15, {1, 2, 3, 4, 5}}
example-1
Example:
iex> partial_fun = Curry.~>>(&Curry.test5/5, 1, 2)
#Function<19.126501267/3 in :erl_eval.expr/5>
iex> partial_fun.(3, 4, 5)
{15, {1, 2, 3, 4, 5}}