import * as A from "../Array"; import { identity } from "../Function"; import type { Tree } from "./model"; /* * ------------------------------------------- * Comonad Tree * ------------------------------------------- */ export const extend_ = (wa: Tree, f: (wa: Tree) => B): Tree => ({ value: f(wa), forest: A.map_(wa.forest, (a) => extend_(a, f)) }); export const extend = (f: (wa: Tree) => B) => (wa: Tree): Tree => extend_(wa, f); export const duplicate: (wa: Tree) => Tree> = extend(identity); export const extract = (wa: Tree): A => wa.value;