View Source Flamel (flamel v1.10.0)

Documentation for Flamel.

Summary

Functions

Checks if something is blank?

Is something a boolean?

Is this a DateTime

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.

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

iex> Flamel.blank?(true)
false

iex> Flamel.blank?(false)
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

Is this a DateTime

Examples

iex> Flamel.datetime?(true)
false

iex> Flamel.datetime?(~U[2021-12-21 18:27:00Z])
true

iex> Flamel.datetime?("2021-12-21T18:27:00Z")
true

See Flamel.Result.error?/1.

See Flamel.Result.ok?/1.

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"}

See Flamel.Wrap.unwrap/1.

See Flamel.Wrap.unwrap_error!/1.

Link to this function

unwrap_error_or_nil(value)

View Source

See Flamel.Wrap.unwrap_error_or_nil/1.

See Flamel.Wrap.unwrap_ok!/1.

See Flamel.Wrap.unwrap_ok_or_nil/1.