Funx.Monoid.Optics.IsoCompose (funx v0.8.0)

View Source

The Funx.Monoid.Optics.IsoCompose module provides a monoid wrapper for sequential iso composition.

This wrapper allows isos to be used with generic monoid operations like m_concat/2 and m_append/3, enabling functional composition of multiple isos into a single bidirectional transformation.

Wrapping and Unwrapping

  • new/1: Wraps an iso in an IsoCompose monoid.
  • unwrap/1: Extracts the iso from an IsoCompose wrapper.

Monoid Operations (via protocol)

  • empty/1: Returns the identity iso (both directions are identity).
  • append/2: Composes two isos sequentially.
  • wrap/2: Wraps an iso value into the monoid.

Examples

iex> alias Funx.Monoid.Optics.IsoCompose
iex> alias Funx.Optics.Iso
iex> isos = [
...>   Iso.make(
...>     fn s -> String.to_integer(s) end,
...>     fn i -> Integer.to_string(i) end
...>   ),
...>   Iso.make(
...>     fn i -> i * 2 end,
...>     fn i -> div(i, 2) end
...>   )
...> ]
iex> composed = Funx.Monoid.Utils.m_concat(%IsoCompose{}, isos)
iex> Iso.view("21", composed)
42

Summary

Functions

Wraps an iso in an IsoCompose monoid.

Extracts the iso from an IsoCompose wrapper.

Types

t()

@type t() :: %Funx.Monoid.Optics.IsoCompose{iso: Funx.Optics.Iso.t()}

Functions

new(iso)

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

Wraps an iso in an IsoCompose monoid.

unwrap(iso_compose)

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

Extracts the iso from an IsoCompose wrapper.