View Source Dreamy.Defaults (dreamy v1.0.0)
Helpers for dealing with Defaults for functions
Summary
Functions
Function for extracting booleans from strings. Useful in configs
Function for extracting the default opts as provided and returns them in a variable sized tuple in defaults order
Function for extracting floats from strings. Useful in configs
Function for extracting integers from strings. Useful in configs
Functions
Function for extracting booleans from strings. Useful in configs
Options
- default: (false) bool to be used when the value could not be parsed
iex> use Dreamy
...> parse_bool("TRUE")
true
...> parse_bool("faLse")
false
...> parse_bool("", default: true)
true
...> parse_bool(nil, default: true)
true
Function for extracting the default opts as provided and returns them in a variable sized tuple in defaults order
iex> use Dreamy
...> opts = [a: 1, b: 2]
...> defaults = [a: -1, b: -2, c: -3]
...> parse_defaults!(opts, defaults)
{1, 2, -3}
Function for extracting floats from strings. Useful in configs
Options
- default: (0.0) float to be used when the value could not be parsed
- remainder_allowed?: (false) wether or not to allow the float to be followed by an arbitrary string
- See Float.parse/1 for more info
iex> use Dreamy
...> parse_float("3.14")
3.14
iex> use Dreamy
...> parse_float("1.23abc", remainder_allowed?: true, default: 0.1)
1.23
iex> use Dreamy
...> parse_float("123abc", remainder_allowed?: false, default: 0.1)
0.1
Function for extracting integers from strings. Useful in configs
Options
- default: (0) int to be used when the value could not be parsed
- base: (10) base to parse the integer as
- remainder_allowed?: (false) wether or not to allow the integer to be followed by an arbitrary string
- See Integer.parse/2 for more info
iex> use Dreamy
...> parse_int("123")
123
iex> use Dreamy
...> parse_int("deadbeef", base: 16)
3735928559
iex> use Dreamy
...> parse_int("123abc", remainder_allowed?: true, default: -1)
123
iex> use Dreamy
...> parse_int("123abc", remainder_allowed?: false, default: -1)
-1