Extra v0.2.0 Tuple.Extra

Extensions to the Tuple module.

Link to this section Summary

Functions

Unwraps an :ok tuple or raises an error

Unwraps an :ok tuple or returns a default value

Wraps data with a tag atom

Link to this section Functions

Link to this function unwrap_ok!(tuple)
unwrap_ok!({:ok, val} | {:error, any}) ::
  val |
  no_return when val: var

Unwraps an :ok tuple or raises an error.

Examples

iex> Tuple.Extra.unwrap_ok!({:ok, 5}) 5

Link to this function unwrap_ok_with_default(arg, default)
unwrap_ok_with_default({:ok, val} | {:error, any}, default) ::
  val |
  default when val: var, default: var

Unwraps an :ok tuple or returns a default value.

Examples

iex> Tuple.Extra.unwrap_ok_with_default({:ok, 5}, 0) 5

iex> Tuple.Extra.unwrap_ok_with_default({:error, :fail}, 0) 0

Link to this function wrap_with(data, atom)
wrap_with(term, atom) :: {atom, term}

Wraps data with a tag atom.

Useful for piping data into :ok and :error tuples.

Examples

iex> Tuple.Extra.wrap_with(5, :ok)