View Source Rivet.Utils.Enum (rivet_utils v1.1.8)

Contributor: Brandon Gillespie

Link to this section Summary

Functions

like Enum.find_value() on a list of [{rx, fn}, ..], calling fn on the matched rx and returning the result. Almost like a case statement (see to_minutes below)

sequence helps you know if any item in a list of tuples failed

Link to this section Functions

like Enum.find_value() on a list of [{rx, fn}, ..], calling fn on the matched rx and returning the result. Almost like a case statement (see to_minutes below)

iex> opts = [ ...> {~r/^(\d+)\s(m|min(s)?|minute(s)?)$/, fn match, _ -> {:min, match} end}, ...> {~r/^(\d+)\s(h|hour(s)?|hr(s)?)$/, fn match, _ -> {:hr, match} end}, ...> ] ...> enum_rx(opts, "30 m")

iex> enum_rx(opts, "1.5 hr") # doesn't match because of the period nil

@spec sequence([keyword()]) :: {:error, any()} | {:ok, [any()]}

sequence helps you know if any item in a list of tuples failed

iex> vals = [ok: 1, ok: 2, ok: 3] ...> sequence(vals)

iex> vals = [ok: 1, error: "nan", ok: 3] ...> sequence(vals)