View Source Witchcraft.Bifunctor.Proto protocol (Witchcraft v1.0.6-doma)
Protocol for the Elixir.Witchcraft.Bifunctor
type class
For this type class's API, please refer to Elixir.Witchcraft.Bifunctor
Link to this section Summary
Functions
map
separate fuctions over two fields in a product type.
Link to this section Types
@type t() :: term()
Link to this section Functions
@spec bimap(Witchcraft.Bifunctor.t(), (any() -> any()), (any() -> any())) :: Witchcraft.Bifunctor.t()
map
separate fuctions over two fields in a product type.
The order of fields doesn't always matter in the map. The first/second function application is determined by the instance. It also does not have to map all fields in a product type.
diagram
Diagram
┌------------------------------------┐
↓ |
%Combo{a: 5, b: :ok, c: "hello"} |> bimap(&(&1 * 100), &String.upcase/1)
↑ |
└---------------------------------┘
#=> %Combo{a: 500, b: :ok, c: "HELLO"}
examples
Examples
iex> {1, "a"} |> bimap(&(&1 * 100), &(&1 <> "!"))
{100, "a!"}
iex> {:msg, 42, "number is below 50"}
...> |> bimap(&(%{subject: &1}), &String.upcase/1)
{:msg, %{subject: 42}, "NUMBER IS BELOW 50"}