View Source Oxide.Result.Dangerous (oxide v0.4.0)

Result helpers you should use with extreme care, or better yet, not at all.

Summary

Functions

Dangerous result pipe operator.

Functions

Dangerous result pipe operator.

The result pipe operator ~>/2 is defined identically to Oxide.Result.&&&/2, and in many circumstances behaves the same:

iex> {:ok, :foo} ~> Atom.to_string()
"foo"
iex> {:ok, 3} ~> then(fn x -> {:ok, x + 1} end) ~> List.wrap()
[4]
iex> {:ok, :foo} ~> Atom.to_string() |> String.capitalize()
"Foo"
iex> {:error, :oops} ~> then(fn x -> {:ok, x + 1} end) ~> List.wrap()
{:error, :oops}

However, Elixir's operator precedence means that when ~> is followed by |>, an early error can pipe into later stages of the pipeline in a way that is almost never what you want.

iex> {:error, :oops} &&& Atom.to_string() |> String.capitalize()
{:error, :oops}
iex> {:error, :oops} ~> Atom.to_string() |> String.capitalize()  # String.capitalize({:error, :oops})
** (FunctionClauseError) no function clause matching in String.capitalize/2