Mandrake v0.0.4 Mandrake.Logic

Mandrake logical functions.

Summary

Functions

Returns true if both functions return true

Returns a function that return !result of the given function

Returns the second argument if it is not nil

Returns true if one function return true

Returns a function that process onTrue or onFalse depending upon the result of the condition

Returns true if value is “”, ‘’, [], {} or %{}

Returns true if both conditions are true

Returns a function that process on_true if condition is true

Returns ! of value

Returns true if one condition is true

Functions

both(first_func, second_func)

Returns true if both functions return true

Examples

iex>  my_function = Mandrake.Logic.both(fn x -> x > 10 end, fn x -> Kernel.rem(x, 2) == 0 end)
...>  my_function.(100)
true
iex>  my_function.(101)
false
complement(function)

Returns a function that return !result of the given function.

Examples

iex>  is_odd = Mandrake.Logic.complement(fn arg -> Kernel.rem(arg, 2) == 0 end)
...>  is_odd.(24)
false
default_to(value)

Returns the second argument if it is not nil.

Examples

iex>  default_to_7 = Mandrake.Logic.default_to(7)
...>  default_to_7.(nil)
7
iex>  default_to_7.(12)
12
either(first_func, second_func)

Returns true if one function return true

Examples

iex>  my_function = Mandrake.Logic.either(fn x -> x > 10 end, fn x -> Kernel.rem(x, 2) == 0 end)
...>  my_function.(100)
true
iex>  my_function.(101)
true
ifElse(condition, onTrue, onFalse)

Returns a function that process onTrue or onFalse depending upon the result of the condition.

Examples

iex>  my_number = 1
...>  my_function = Mandrake.Logic.ifElse(my_number <= 1, fn arg -> Mandrake.Math.inc(arg) end, fn arg -> Mandrake.Math.dec(arg) end)
...>  my_function.(my_number)
2
is_empty(value)

Returns true if value is “”, ‘’, [], {} or %{}.

Examples

iex>  Mandrake.Logic.is_empty([])
true
iex>  Mandrake.Logic.is_empty(nil)
false
logic_and(first_cond, second_cond)

Returns true if both conditions are true.

Examples

iex>  Mandrake.Logic.logic_and(1<2, 3>4)
false
logic_if(condition, on_true)

Returns a function that process on_true if condition is true.

Examples

iex>  my_number = 1
...>  my_function = Mandrake.Logic.logic_if(my_number <= 1, fn arg -> Mandrake.Math.inc(arg) end)
...>  my_function.(my_number)
2
logic_not(value)

Returns ! of value

Examples

iex>  Mandrake.Logic.logic_not(false)
true
logic_or(first_cond, second_cond)

Returns true if one condition is true.

Examples

iex>  Mandrake.Logic.logic_or(1<2, 3>4)
true