Prism (focus v0.4.0)
Prisms are like lenses, but used when the view focused on may not exist.
This includes sum types; although not backed by an explicit Maybe type, the [{:ok, any} | {:error}] convention is explicitly supported as a value that a prism can focus on.
Link to this section Summary
Link to this section Types
Link to this section Functions
Link to this function
error()
Specs
error() :: t()
A prism that matches an {:error, } tuple. Note that on a successful match, view/set/over will return {:ok, }
Examples
iex> error = Prism.error
iex> error |> Focus.view({:error, 5})
{:ok, 5}
iex> error |> Focus.set({:error, 5}, "Banana")
{:ok, "Banana"}
iex> error |> Focus.view({:ok, :oops})
{:error, {:prism, :bad_path}}
Specs
ok() :: t()
A prism that matches an {:ok, _} tuple.
Examples
iex> ok = Prism.ok
iex> ok |> Focus.view({:ok, 5})
{:ok, 5}
iex> ok |> Focus.set({:ok, 5}, "Banana")
{:ok, "Banana"}
iex> ok |> Focus.view({:error, :oops})
{:error, {:prism, :bad_path}}