Funx.Monoid.Optics.LensCompose (funx v0.8.2)

View Source

The 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

  • new/1: Wraps a lens in a LensCompose monoid.
  • unwrap/1: Extracts the lens from a LensCompose wrapper.

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

Functions

Wraps a lens in a LensCompose monoid.

Extracts the lens from a LensCompose wrapper.

Types

t()

@type t() :: %Funx.Monoid.Optics.LensCompose{lens: Funx.Optics.Lens.t()}

Functions

new(lens)

@spec new(Funx.Optics.Lens.t()) :: t()

Wraps a lens in a LensCompose monoid.

unwrap(lens_compose)

@spec unwrap(t()) :: Funx.Optics.Lens.t()

Extracts the lens from a LensCompose wrapper.