Documentation

Hale.Base.Data.Traversable

class Data.Traversable (T : Type u → Type u) extends Functor T :
Type (u + 1)

Traversable captures structures that can be traversed left-to-right, performing an applicative action at each element and collecting results.

For a traversable $T$ and applicative $G$: $$\text{traverse} : (\alpha \to G\,\beta) \to T\,\alpha \to G\,(T\,\beta)$$ $$\text{sequence} : T\,(G\,\alpha) \to G\,(T\,\alpha)$$

The key insight: traverse generalizes both map (using Identity) and foldMap (using Const).

  • map {α β : Type u} : (αβ)T αT β
  • mapConst {α β : Type u} : αT βT α
  • traverse {α β : Type u} {G : Type u → Type u} [Applicative G] : (αG β)T αG (T β)

    Traverse a structure, applying an effectful function to each element and collecting results. $$\text{traverse}(f, [x_1, \ldots, x_n]) = f(x_1) \circledast f(x_2) \circledast \cdots \circledast f(x_n)$$ where $\circledast$ denotes applicative combination.

Instances
    @[inline]
    def Data.Traversable.sequence {T : Type u → Type u} {α : Type u} [Traversable T] {G : Type u → Type u} [Applicative G] (t : T (G α)) :
    G (T α)

    Sequence effectful values left-to-right. $$\text{sequence}([m_1, \ldots, m_n]) = m_1 \circledast m_2 \circledast \cdots \circledast m_n$$ Equivalent to traverse id.

    Equations
    Instances For

      Laws for a lawful traversable functor.

      Identity: Traversing with pure is pure. $$\text{traverse}(\text{pure}) = \text{pure}$$

      Naturality: Natural transformations commute with traverse.

      Instances
        @[implicit_reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[implicit_reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[implicit_reducible]
        Equations
        • One or more equations did not get rendered due to their size.