View Source Flamel (flamel v1.0.0)

Documentation for Flamel.

Summary

Functions

Checks if something is blank?

Is something a boolean?

Checks if something is present?

Converts to an atom. Warning: This uses String.to_atom

Convert something to a boolean

Converts to a float

Converts to an integer

Converts to a map

Converts to a string

Turn an exception into an error tuple. This can be used with with to catch exceptions and turn them into error tuples.

Takes an {:ok, value} or {:error, message} tuple and returns the value

Takes an {:ok, value} tuple and returns the value

Takes an {:error, value} tuple and returns the value or nil

Takes an {:ok, value} tuple and returns the value

Takes an {:ok, value} tuple and returns the value or nil

Functions

Checks if something is blank?

Examples

iex> Flamel.blank?(nil)
true

iex> Flamel.blank?("hello world")
false

iex> Flamel.blank?(%{})
true

iex> Flamel.blank?(%{active: true})
false

iex> Flamel.blank?([])
true

iex> Flamel.blank?(["one"])
false

iex> Flamel.blank?("       ")
true

iex> Flamel.blank?(0)
false

iex> Flamel.blank?(1)
false

Is something a boolean?

Examples

iex> Flamel.boolean?(true)
true

iex> Flamel.boolean?(false)
true

iex> Flamel.boolean?(nil)
false

iex> Flamel.boolean?("true")
false

Checks if something is present?

Examples

iex> Flamel.present?(nil)
false

iex> Flamel.present?("hello world")
true

iex> Flamel.present?(%{})
false

iex> Flamel.present?(%{active: true})
true

iex> Flamel.present?([])
false

iex> Flamel.present?(["one"])
true

iex> Flamel.present?("         ")
false

iex> Flamel.present?(0)
true

iex> Flamel.present?(1)
true

Converts to an atom. Warning: This uses String.to_atom

Examples

iex> Flamel.to_atom(:test)
:test

iex> Flamel.to_atom("test")
:test

iex> Flamel.to_atom(1)
:"1"

iex> Flamel.to_atom(1.1)
:"1.1"

Convert something to a boolean

Examples

iex> Flamel.to_boolean("Y")
true

iex> Flamel.to_boolean("y")
true

iex> Flamel.to_boolean("YES")
true

iex> Flamel.to_boolean("Yes")
true

iex> Flamel.to_boolean("yes")
true

iex> Flamel.to_boolean("true")
true

iex> Flamel.to_boolean("TRUE")
true

iex> Flamel.to_boolean(1)
true

iex> Flamel.to_boolean(true)
true 

iex> Flamel.to_boolean("N")
false

iex> Flamel.to_boolean("n")
false

iex> Flamel.to_boolean("NO")
false

iex> Flamel.to_boolean("No")
false

iex> Flamel.to_boolean("no")
false

iex> Flamel.to_boolean("false")
false

iex> Flamel.to_boolean(0)
false

iex> Flamel.to_boolean(false)
false

Converts to a float

Examples

iex> Flamel.to_float("1.2")
1.2

iex> Flamel.to_float(1.2)
1.2

iex> Flamel.to_float(1)
1.0

iex> Flamel.to_float(nil)
0.0

Converts to an integer

Examples

iex> Flamel.to_integer("1")
1

iex> Flamel.to_integer(1)
1

iex> Flamel.to_integer(1.2)
1

iex> Flamel.to_integer(nil)
0

Converts to a map

Converts to a string

Examples

iex> Flamel.to_string(nil)
""

iex> Flamel.to_string("test")
"test"

iex> Flamel.to_string(:test)
"test"

iex> Flamel.to_string(2.3)
"2.3"

iex> Flamel.to_string(1)
"1"

iex> Flamel.to_string(1)
"1"
Link to this function

try_and_return(callable, ret \\ nil)

View Source
@spec try_and_return((... -> any()), any()) :: any() | {:error, binary()}

Turn an exception into an error tuple. This can be used with with to catch exceptions and turn them into error tuples.

Examples

iex> Flamel.try_and_return(fn -> :ok end)
:ok

iex> Flamel.try_and_return(fn -> raise "error" end, {:ok, :default_value})
{:ok, :default_value}

iex> Flamel.try_and_return(fn -> raise "error" end)
{:error, "error"}

Takes an {:ok, value} or {:error, message} tuple and returns the value

Examples

iex> Flamel.unwrap({:ok, []})
[]

iex> Flamel.unwrap({:error, "message"})
"message"

Takes an {:ok, value} tuple and returns the value

Examples

iex> Flamel.unwrap_error!({:ok, []})
** (ArgumentError) {:ok, []} is not an :error tuple

iex> Flamel.unwrap_error!({:error, "message"})
"message"
Link to this function

unwrap_error_or_nil(arg1)

View Source

Takes an {:error, value} tuple and returns the value or nil

Examples

iex> Flamel.unwrap_error_or_nil({:ok, []})
nil

iex> Flamel.unwrap_error_or_nil({:error, "message"})
"message"

Takes an {:ok, value} tuple and returns the value

Examples

iex> Flamel.unwrap_ok!({:ok, []})
[]

iex> Flamel.unwrap_ok!({:error, "message"})
** (ArgumentError) {:error, "message"} is not an :ok tuple

Takes an {:ok, value} tuple and returns the value or nil

Examples

iex> Flamel.unwrap_ok_or_nil({:ok, []})
[]

iex> Flamel.unwrap_ok_or_nil({:error, "message"})
nil