Fxnk v0.1.1 Fxnk.Logic View Source
Fxnk.Logic
are functions for dealing with booleans.
Link to this section Summary
Functions
and?
returns true if both inputs are the same, opposite of is_not/2
.
Curried both?/3
.
both?/3
takes an input and two predicate functions, returning true if both functions
are true when passed the input.
complement/1
returns the opposite of the boolean passed to it.
Curried default_to/2
default_to/2
takes two values and returns the right side value if the left side is false
or nil
Curried either/3
either?/3
takes an input and two predicate functions and returns true if either predicate is true.
Curried greater than function, returns a function that returns true if the second number passed in is greater than the first.
is_empty/1
returns true if passed an empty Map
or List
.
Curried is_not?/2
is_not/3
returns true if both inputs are not the same, opposite of and?/2
Curried less than function, returns a function that returns true if the second number passed in is less than the first.
Checks if a value is equal to nil
.
## Examples
Curried or/2
or/2
returns true if one or both of its arguments are true.
Link to this section Functions
Specs
Curried and?/2
.
Examples
iex> isTwo? = Fxnk.Logic.and?(2)
iex> isTwo?.(2)
true
iex> isTwo?.(3)
false
Specs
and?
returns true if both inputs are the same, opposite of is_not/2
.
Examples
iex> Fxnk.Logic.and?(2, 2)
true
iex> Fxnk.Logic.and?("hello", "world")
false
Specs
Curried both?/3
.
Examples
iex> gt10lt20? = Fxnk.Logic.both?(fn x -> x > 10 end, fn x -> x < 20 end)
iex> gt10lt20?.(15)
true
iex> gt10lt20?.(30)
false
Specs
both?/3
takes an input and two predicate functions, returning true if both functions
are true when passed the input.
Examples
iex> Fxnk.Logic.both?(15, fn x -> x > 10 end, fn x -> x < 20 end)
true
iex> Fxnk.Logic.both?(30, fn x -> x > 10 end, fn x -> x < 20 end)
false
Specs
complement/1
returns the opposite of the boolean passed to it.
Examples
iex> Fxnk.Logic.complement(true)
false
iex> Fxnk.Logic.complement(false)
true
Specs
Curried default_to/2
Examples
iex> defaultTo42 = Fxnk.Logic.default_to(42)
iex> defaultTo42.(false)
42
iex> defaultTo42.(nil)
42
iex> defaultTo42.("thanks for all the fish")
"thanks for all the fish"
Specs
default_to/2
takes two values and returns the right side value if the left side is false
or nil
Examples
iex> false |> Fxnk.Logic.default_to(42)
42
iex> nil |> Fxnk.Logic.default_to(42)
42
iex> "hello, world" |> Fxnk.Logic.default_to(42)
"hello, world"
Specs
Curried either/3
Examples
iex> lt10orGt30? = Fxnk.Logic.either?(fn x -> x < 10 end, fn x -> x > 30 end)
iex> lt10orGt30?.(5)
true
iex> lt10orGt30?.(15)
false
Specs
either?/3
takes an input and two predicate functions and returns true if either predicate is true.
Examples
iex> Fxnk.Logic.either?(5, fn x -> x < 10 end, fn x -> x > 30 end)
true
iex> Fxnk.Logic.either?(15, fn x -> x < 10 end, fn x -> x > 30 end)
false
Specs
Curried greater than function, returns a function that returns true if the second number passed in is greater than the first.
Examples
iex> greaterThan5? = Fxnk.Logic.gt?(5) iex> greaterThan5?.(19) true iex> greaterThan5?.(3) false
Specs
is_empty/1
returns true if passed an empty Map
or List
.
Examples
iex> Fxnk.Logic.is_empty([])
true
iex> Fxnk.Logic.is_empty(%{})
true
iex> Fxnk.Logic.is_empty([1,1,2,3,5,8])
false
Specs
Curried is_not?/2
Examples
iex> isNotThree = Fxnk.Logic.is_not?(3)
iex> isNotThree.(3)
false
iex> isNotThree.(4)
true
Specs
is_not/3
returns true if both inputs are not the same, opposite of and?/2
Examples
iex> Fxnk.Logic.is_not?(3, 3)
false
iex> Fxnk.Logic.is_not?(3, 4)
true
Specs
Curried less than function, returns a function that returns true if the second number passed in is less than the first.
Examples
iex> lessThan5? = Fxnk.Logic.lt?(5) iex> lessThan5?.(19) false iex> lessThan5?.(3) true
Specs
Checks if a value is equal to nil
.
Examples
iex> Fxnk.Logic.nil?(nil)
true
iex> Fxnk.Logic.nil?("not nil")
false
Specs
## Examples
iex> Fxnk.Logic.not_nil?(nil)
false
iex> Fxnk.Logic.not_nil?("not nil")
true
Specs
Curried or/2
Examples
iex> willBeTrue = Fxnk.Logic.or?(true) iex> willBeTrue.(false) true
Specs
or/2
returns true if one or both of its arguments are true.
Examples
iex> Fxnk.Logic.or?(true, false)
true
iex> Fxnk.Logic.or?(true, true)
true
iex> Fxnk.Logic.or?(false, false)
false