Funx.Monoid.Optics.LensCompose (funx v0.8.2)
View SourceThe Funx.Monoid.Optics.LensCompose module provides a monoid wrapper for sequential lens composition.
This wrapper allows lenses to be used with generic monoid operations like m_concat/2 and m_append/3,
enabling functional composition of multiple lenses into a single focusing operation.
Wrapping and Unwrapping
Monoid Operations (via protocol)
empty/1: Returns the identity lens (leaves structure unchanged).append/2: Composes two lenses sequentially (outer then inner).wrap/2: Wraps a lens value into the monoid.
Examples
iex> alias Funx.Monoid.Optics.LensCompose
iex> alias Funx.Optics.Lens
iex> lenses = [
...> Lens.key(:profile),
...> Lens.key(:score)
...> ]
iex> wrapped = Enum.map(lenses, &LensCompose.new/1)
iex> composed = Funx.Monoid.Utils.m_concat(%LensCompose{}, lenses)
iex> %{profile: %{score: 42}} |> Lens.view!(composed)
42
Summary
Types
@type t() :: %Funx.Monoid.Optics.LensCompose{lens: Funx.Optics.Lens.t()}
Functions
@spec new(Funx.Optics.Lens.t()) :: t()
Wraps a lens in a LensCompose monoid.
@spec unwrap(t()) :: Funx.Optics.Lens.t()
Extracts the lens from a LensCompose wrapper.