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).
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
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.
- traverse_identity {α : Type u} (t : T α) : Traversable.traverse Functor.Identity.mk t = { runIdentity := t }
Traversing with
pure(Identity) is identity. $$\text{traverse}(\text{Identity.mk}) = \text{Identity.mk}$$
Instances
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.