import type { Recursive } from "@tsplus/stdlib/prelude/Recursive/definition" /** * Use a `Covariant` and a `Recursive.Fn` function to perform a *depth-first* reduction * of the `Recursive` structure. The supplied function will receive the current term * with all of its recursive elements replaced by the computed value of its children, * i.e. a _catamorphism_ * * @tsplus static Recursive/Aspects fold * @tsplus pipeable Recursive fold */ export function fold( F: Covariant, f: Recursive.Fn ) { return (self: Recursive) => go(self) function go(term: Recursive): Z { return f(F.map(go)(term.caseValue)) } }