Fxnk v0.1.1 Fxnk.Logic View Source

Fxnk.Logic are functions for dealing with booleans.

Link to this section Summary

Functions

Curried and?/2.

and? returns true if both inputs are the same, opposite of is_not/2.

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.

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.

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

and?(any()) :: (... -> any())

Curried and?/2.

Examples

iex> isTwo? = Fxnk.Logic.and?(2)
iex> isTwo?.(2)
true
iex> isTwo?.(3)
false

Specs

and?(any(), any()) :: boolean()

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

both?(function(), function()) :: (... -> any())

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
Link to this function

both?(input, func1, func2)

View Source

Specs

both?(function(), function(), any()) :: boolean()

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(boolean()) :: boolean()

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

default_to(any()) :: (... -> any())

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(any(), any()) :: any()

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

either?(function(), function()) :: (... -> any())

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
Link to this function

either?(input, func1, func2)

View Source

Specs

either?(any(), function(), function()) :: any()

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

gt?(number()) :: (... -> any())

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(any()) :: boolean()

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

is_not?(any()) :: (... -> any())

Curried is_not?/2

Examples

iex> isNotThree = Fxnk.Logic.is_not?(3)
iex> isNotThree.(3)
false
iex> isNotThree.(4)
true

Specs

is_not?(any(), any()) :: boolean()

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

lt?(number()) :: (... -> any())

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

nil?(any()) :: boolean()

Checks if a value is equal to nil.

Examples

iex> Fxnk.Logic.nil?(nil)
true
iex> Fxnk.Logic.nil?("not nil")
false

Specs

not_nil?(any()) :: boolean()

## Examples

iex> Fxnk.Logic.not_nil?(nil)
false
iex> Fxnk.Logic.not_nil?("not nil")
true

Specs

or?(any()) :: (... -> any())

Curried or/2

Examples

iex> willBeTrue = Fxnk.Logic.or?(true) iex> willBeTrue.(false) true

Specs

or?(any(), any()) :: boolean()

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