ex_commons v0.1.3 ExCommons
Link to this section Summary
Functions
Deconstructs tuples to return their output, will raise on error and on unknown tuples
Drops all mime types from a string
Converts nil to any value, defaults to 0. Can iterate over lists, and maps, and keyword lists (also handles tuples). It will change only values of the enumerable/tuple types
Transforms module name to key, useful for polymorphism in ecto associations
Link to this section Functions
Deconstructs tuples to return their output, will raise on error and on unknown tuples.
Examples
iex> ExCommons.deconstruct({:ok, "Output"})
"Output"
iex> ExCommons.deconstruct({:safe, "Safe"})
"Safe"
iex> ExCommons.deconstruct({:error, %{message: "Error"}})
** (RuntimeError) Error
iex> ExCommons.deconstruct({:unknown, nil})
** (RuntimeError) Can't handle :unknown.
Drops all mime types from a string
Examples
iex> ExCommons.drop_mimes(“file_name.pdf”) “file_name”
iex> ExCommons.drop_mimes(“file.with.three.mimes”) “file”
Converts nil to any value, defaults to 0. Can iterate over lists, and maps, and keyword lists (also handles tuples). It will change only values of the enumerable/tuple types.
Examples
iex> ExCommons.escape_nil(nil) 0
iex> ExCommons.escape_nil(nil, “”) “”
iex> ExCommons.escape_nil(123) 123
iex> ExCommons.escape_nil([1.23, 456, nil]) [1.23, 456, 0]
iex> ExCommons.escape_nil([a: “a”, b: “b”, c: nil], “c”) [a: “a”, b: “b”, c: “c”]
## Warning: it will reorder the map. iex> ExCommons.escape_nil(%{c: nil, a: “a”, b: “b”}, “c”) %{a: “a”, b: “b”, c: “c”}
Transforms module name to key, useful for polymorphism in ecto associations.
Examples
iex> ExCommons.module_to_key(Some.ModuleName)
:module_name
iex> ExCommons.module_to_key("SomeString")
{:error, %{message: "SomeString is not module name"}}