Zodish.Helpers (zodish v0.2.4)

View Source

Common utility functions.

Summary

Functions

Infers the type of a value, returning its spec's AST.

Pluralizes a given word based on common English rules.

Pluralizes a word based on the given count.

Same as Keyword.take/2 but the keys are sorted in the same order you provided them.

Returns the name of the given module without the "Elixir." prefix.

Returns the type of the given value.

Prints a warning message the returns the value given as first argument.

Functions

i(value)

@spec i(value :: any()) :: String.t()

Alias to Kernel.inspect/1.

infer_type(value)

@spec infer_type(value :: term()) :: Macro.t()

Infers the type of a value, returning its spec's AST.

pluralize(word)

@spec pluralize(word :: String.t()) :: String.t()

Pluralizes a given word based on common English rules.

iex> pluralize("is")
"are"

iex> pluralize("Was")
"Were"

iex> pluralize("cat")
"cats"

iex> pluralize("baby")
"babies"

iex> pluralize("box")
"boxes"

iex> pluralize("leaf")
"leaves"

iex> pluralize("man")
"men"

iex> pluralize("church")
"churches"

pluralize(count, arg)

@spec pluralize(count :: non_neg_integer(), word :: String.t()) :: String.t()

Pluralizes a word based on the given count.

iex> pluralize(1, "cat")
"cat"

iex> pluralize(0, "cat")
"cats"

iex> pluralize(2, "cat")
"cats"

take_sorted(keyword, keys)

Same as Keyword.take/2 but the keys are sorted in the same order you provided them.

iex> value =[foo: 1, bar: 2, baz: 3]
iex> take_sorted(value, [:bar, :baz, :foo])
[bar: 2, baz: 3, foo: 1]

to_mod_name(mod)

@spec to_mod_name(mod :: module()) :: String.t()

Returns the name of the given module without the "Elixir." prefix.

iex> to_string(Zodish.Type.Map)
"Elixir.Zodish.Type.Map"

iex> to_mod_name(Zodish.Type.Map)
"Zodish.Type.Map"

typeof(value)

@spec typeof(value) :: String.t()
when value:
       nil
       | boolean()
       | atom()
       | binary()
       | bitstring()
       | float()
       | integer()
       | list()
       | keyword()
       | struct()
       | map()
       | tuple()
       | function()
       | pid()
       | port()
       | reference()

Returns the type of the given value.

warn(value, message)

@spec warn(value, message :: String.t()) :: value when value: any()

Prints a warning message the returns the value given as first argument.