View Source Funx.Monad.Identity (funx v0.2.3)
The Funx.Monad.Identity module represents the identity monad, where values are simply wrapped in a structure
and operations are applied directly to those values.
Functions
pure/1: Wraps a value in theIdentitymonad.extract/1: Extracts the wrapped value from anIdentity.tap/2: Executes a side-effect function on the wrapped value, returning the originalIdentityunchanged.
Protocols
This module implements the following protocols:
Funx.Monad: Implements thebind/2,map/2, andap/2functions for monadic operations.Funx.Eq: Defines equality checks forIdentityvalues.Funx.Ord: Defines ordering logic forIdentityvalues.String.Chars: Converts anIdentityvalue into a string representation.
Summary
Functions
Extracts the value from an Identity.
Creates a new Identity value by wrapping a given value.
Executes a side-effect function on the wrapped value and returns the original Identity unchanged.
Types
@type t(value) :: %Funx.Monad.Identity{value: value}
Functions
Extracts the value from an Identity.
Examples
iex> Funx.Monad.Identity.extract(Funx.Monad.Identity.pure(5))
5
@spec lift_eq(Funx.Eq.Utils.eq_map()) :: Funx.Eq.Utils.eq_map()
@spec lift_ord(Funx.Ord.Utils.ord_map()) :: Funx.Ord.Utils.ord_map()
Creates a new Identity value by wrapping a given value.
Examples
iex> Funx.Monad.Identity.pure(5)
%Funx.Monad.Identity{value: 5}
Executes a side-effect function on the wrapped value and returns the original Identity unchanged.
Useful for debugging, logging, or performing side effects in the middle of a pipeline without changing the value.
Examples
iex> Funx.Monad.Identity.pure(5) |> Funx.Monad.Identity.tap(fn x -> x * 2 end)
%Funx.Monad.Identity{value: 5}