Fxnk v0.1.1 Fxnk.Functions View Source

Fxnk.Functions are functions for computation or helpers.

Link to this section Summary

Functions

always/1 returns the value passed to it always.

always/2 returns the second value passed to it always.

converge/3 takes an initial argument, a function and a list of functions. It applies the argument to each of the list of functions and then applies the results of those functions as the argument to the end function.

curry/1 takes a function and returns a function.

A function that always returns false.

Takes a function, returns a function that takes the same args as the initial function, but flips the order of the arguments.

Same as flip/1, but takes the arguments at the same time as the function.

identity/1 returns what was passed to it.

juxt/1 takes list of functions and returns a curried juxt.

juxt/2 takes an initial argument and list of functions and applies the functions to the argument.

tap/1 takes a function and returns a function that takes a value. Applies the value to the function and then returns the value.

tap/2 takes a value and a function, applies the value to the function and returns the value.

Function that always returns true.

Link to this section Functions

Specs

always(any()) :: function()

always/1 returns the value passed to it always.

Examples

iex> fourtyTwo = Fxnk.Functions.always(42)
iex> fourtyTwo.("hello")
42

Specs

always(any(), any()) :: any()

always/2 returns the second value passed to it always.

Examples

iex> Fxnk.Functions.always("hello", 42)
42

Specs

converge(function(), [function(), ...]) :: function()

Curried converge/3

Example

iex> reverseUpcaseConcat = Fxnk.Functions.converge(&Fxnk.String.concat/2, [&String.reverse/1, &String.upcase/1]) iex> reverseUpcaseConcat.("hello") "ollehHELLO"

Link to this function

converge(args, to_fn, fns)

View Source

Specs

converge(any(), function(), [function(), ...]) :: any()

converge/3 takes an initial argument, a function and a list of functions. It applies the argument to each of the list of functions and then applies the results of those functions as the argument to the end function.

The end function must have the same arity as the length of the list of functions.

Example

iex> Fxnk.Functions.converge("hello", &Fxnk.String.concat/2, [&String.reverse/1, &String.upcase/1])
"ollehHELLO"

Specs

curry(function()) :: function()

curry/1 takes a function and returns a function.

Examples

iex> add = Fxnk.Functions.curry(fn (a, b) -> a + b end)
iex> add.(6).(7)
13
iex> addOne = Fxnk.Functions.curry(add.(1))
iex> addOne.(1336)
1337

Specs

falsy() :: false

A function that always returns false.

Specs

flip(function()) :: (any(), any() -> any())

Takes a function, returns a function that takes the same args as the initial function, but flips the order of the arguments.

Example

iex> flippedConcatString = Fxnk.Functions.flip(&Fxnk.String.concat/2)
iex> Fxnk.String.concat("hello", "world")
"helloworld"
iex> flippedConcatString.("hello", "world")
"worldhello"

Specs

flip(any(), any(), function()) :: any()

Same as flip/1, but takes the arguments at the same time as the function.

Example

iex> Fxnk.Functions.flip("hello", "world", &Fxnk.String.concat/2)
"worldhello"

Specs

identity(any()) :: any()

identity/1 returns what was passed to it.

Example

iex> Fxnk.Functions.identity(42)
42

Specs

juxt([function(), ...]) :: function()

juxt/1 takes list of functions and returns a curried juxt.

Example

iex> minmax = Fxnk.Functions.juxt([&Fxnk.Math.min/1, &Fxnk.Math.max/1])
iex> minmax.([1,3,5,7])
[1, 7]

Specs

juxt(any(), [function(), ...]) :: any()

juxt/2 takes an initial argument and list of functions and applies the functions to the argument.

Example

iex> Fxnk.Functions.juxt(%{foo: "foo", bar: "bar", baz: "baz"}, [Fxnk.Map.prop(:foo), Fxnk.Map.prop(:bar)])
["foo", "bar"]

Specs

tap(function()) :: function()

tap/1 takes a function and returns a function that takes a value. Applies the value to the function and then returns the value.

Example

iex> function = Fxnk.Functions.tap(&Fxnk.Math.inc/1)
iex> function.(42)
42

Specs

tap(any(), function()) :: function()

tap/2 takes a value and a function, applies the value to the function and returns the value.

Example

iex> Fxnk.Functions.tap(42, &Fxnk.Math.inc/1)
42

Specs

truthy() :: true

Function that always returns true.

Example

iex> Fxnk.Functions.truthy()
true