Fxnk v0.1.1 Fxnk.Flow View Source

Fxnk.Flow functions are used for control flow.

Link to this section Summary

Functions

compose/2 takes an input and a list of functions and runs the functions against the input from right to left.

if_else/4 takes an input, a predicate, a pass function and a fail function. Runs the pass function if the predicate returns true when passed the input, otherwise runs the fail function.

Curried pipe/2.

pipe/2 takes an input and a list of functions and runs the functions against the input from left to right.

unless_is is a logic flow function, which takes an input, a predicate function, and an action function, allowing the action function to run unless the input returns true when ran against the predicate.

until/3 takes an input, a predicate function and an action function, running the action function on the input until the predicate is satisfied.

when_is is a logic flow function, which takes an input, a predicate function, and an action function, allowing the action function to run when the input returns true when ran against the predicate.

Link to this section Functions

Specs

compose([function(), ...]) :: (... -> any())

Curried compose/2.

Examples

iex> reverseSort = Fxnk.Flow.compose([&Enum.reverse/1, &Enum.sort/1])
iex> reverseSort.([1,3,5,7,6,4,2])
[7, 6, 5, 4, 3, 2, 1]

Specs

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

compose/2 takes an input and a list of functions and runs the functions against the input from right to left.

Examples

iex> [1,3,5,7,6,4,2] |> Fxnk.Flow.compose([&Enum.reverse/1, &Enum.sort/1])
[7, 6, 5, 4, 3, 2, 1]
Link to this function

if_else(pred, passFunc, failFunc)

View Source

Specs

if_else(function(), function(), function()) :: (... -> any())

Curried if_else/3

Examples

iex> multTwoIfLessThanTenOrDivideByTwo = Fxnk.Flow.if_else(fn x -> x < 10 end, fn x -> x * 2 end, fn x -> div(x, 2) end)
iex> multTwoIfLessThanTenOrDivideByTwo.(5)
10
iex> multTwoIfLessThanTenOrDivideByTwo.(20)
10
Link to this function

if_else(input, pred, passFunc, failFunc)

View Source

Specs

if_else(any(), function(), function(), function()) :: any()

if_else/4 takes an input, a predicate, a pass function and a fail function. Runs the pass function if the predicate returns true when passed the input, otherwise runs the fail function.

Examples

iex> Fxnk.Flow.if_else(5, fn x -> x < 10 end, fn x -> x * 2 end, fn x -> div(x, 2) end)
10
iex> Fxnk.Flow.if_else(20, fn x -> x < 10 end, fn x -> x * 2 end, fn x -> div(x, 2) end)
10

Specs

pipe([function(), ...]) :: (... -> any())

Curried pipe/2.

Examples

iex> reverseSort = Fxnk.Flow.pipe([&Enum.sort/1, &Enum.reverse/1])
iex> reverseSort.([1,3,5,7,6,4,2])
[7, 6, 5, 4, 3, 2, 1]

Specs

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

pipe/2 takes an input and a list of functions and runs the functions against the input from left to right.

Examples

iex> [1,3,5,7,6,4,2] |> Fxnk.Flow.pipe([&Enum.sort/1, &Enum.reverse/1])
[7, 6, 5, 4, 3, 2, 1]

Specs

unless_is(function(), function()) :: (... -> any())

Curried unless_is/3.

Examples

iex> multiplyByTwoUnlessGreaterThan10 = Fxnk.Flow.unless_is(fn n -> n > 10 end, fn x -> x * 2 end)
iex> multiplyByTwoUnlessGreaterThan10.(15)
15
iex> multiplyByTwoUnlessGreaterThan10.(2)
4
Link to this function

unless_is(input, pred, func)

View Source

Specs

unless_is(any(), function(), function()) :: any()

unless_is is a logic flow function, which takes an input, a predicate function, and an action function, allowing the action function to run unless the input returns true when ran against the predicate.

Example

iex> Fxnk.Flow.unless_is(15, fn n -> n > 10 end, fn x -> x * 2 end)
15
iex> Fxnk.Flow.unless_is(2, fn n -> n > 10 end, fn x -> x * 2 end)
4

Specs

until(function(), function()) :: (... -> any())

Curried until/3.

Examples

iex> timesTwoUntilGreaterThan100 = Fxnk.Flow.until(fn x -> x > 100 end, fn n -> n * 2 end)
iex> timesTwoUntilGreaterThan100.(1)
128

Specs

until(any(), function(), function()) :: any()

until/3 takes an input, a predicate function and an action function, running the action function on the input until the predicate is satisfied.

Examples

iex> Fxnk.Flow.until(1, fn x -> x > 100 end, fn n -> n * 2 end)
128

Specs

when_is(function(), function()) :: (... -> any())

Curried when_is/3.

Examples

iex> timesTwoWhenGreaterThan10 = Fxnk.Flow.when_is(fn x -> x > 10 end, fn n -> n * 2 end)
iex> timesTwoWhenGreaterThan10.(15)
30
iex> timesTwoWhenGreaterThan10.(5)
5
Link to this function

when_is(input, pred, func)

View Source

Specs

when_is(any(), function(), function()) :: any()

when_is is a logic flow function, which takes an input, a predicate function, and an action function, allowing the action function to run when the input returns true when ran against the predicate.

Examples

iex> Fxnk.Flow.when_is(15, fn x -> x > 10 end, fn n -> n * 2 end)
30
iex> Fxnk.Flow.when_is(5, fn x -> x > 10 end, fn n -> n * 2 end)
5