dev.constructive.eo.schemes
Recursion schemes as composable optics: Schemes.cata (fold), Schemes.ana (unfold) and Schemes.hylo (refold) over any type with a Plated instance — stack-safe, expressed as eo optics so they cross-compose with the rest of the library (ana(…).cross(cata(…)) '''is''' hylo).
Attributes
Members list
Type members
Classlikes
Recursion schemes as composable optics, built on the core optic surface.
Recursion schemes as composable optics, built on the core optic surface.
- cata is a
Getter[S, A]driven byPlated[S]— the structural fold, generalisingPlated.transformfromS => StoS => A. - ana is a
Review[S, Seed]— the unfold (buildSfrom a seed), taking a Coalg. - hylo is a fused
Getter[Seed, A]— refold with no intermediateSbuilt.
Because they produce core optic types, they compose with the rest of the optic algebra: someLens.andThen(cata(alg)), and the materializing ana(…).cross(cata(…)) (via the core Optic.cross combinator) — the latter equal to hylo on the same computation (the hylo law).
Two usage modes. Run the optic directly (cata(alg).get(tree), ana(coalg).reverseGet(seed), hylo(expand, alg).get(seed)) — or hand it to capability-consuming code: the concrete optic types implement the capability traits, so a cata / hylo result satisfies CanGet[S, A] (and CanFold[S, A]) and an ana result satisfies CanReverseGet[S, Seed], meaning a consuming signature like
def report[S](s: S)(using g: CanGet[S, Int]): String
accepts a catamorphism without ever naming Getter.
The fold schemes (cata / hylo) take an algebra (N, PSVec[R]) => R — a node plus its already-folded children (paramorphism-flavored). The build scheme (ana) takes a Coalg, the canonical anamorphism shape: a seed yields its child seeds together with how to assemble the node. Both run on one stack-safe engine: a < 512-deep on-stack fast path (no heap frames) that falls back, per deep subtree, to a heap ArrayDeque machine — the same hybrid as Plated.transform. Shallow trees pay no frame allocation; arbitrarily deep ones stay stack-safe.
Attributes
- Source
- Schemes.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Schemes.type