/** * This file contains a collection of utilities and algebraic structure * implementations for Tree. * * @module Tree * @since 2.0.0 */ import "./_dnt.polyfills.js"; import type { $, Kind, Out } from "./kind.js"; import type { Applicable } from "./applicable.js"; import type { Comparable } from "./comparable.js"; import type { Flatmappable } from "./flatmappable.js"; import type { Foldable } from "./foldable.js"; import type { Mappable } from "./mappable.js"; import type { Showable } from "./showable.js"; import type { Traversable } from "./traversable.js"; import type { Wrappable } from "./wrappable.js"; /** * A Forest is an array of Trees. * * @since 2.0.0 */ export type Forest = ReadonlyArray>; /** * A Tree is a node with a single value and a Forest of children. * * @since 2.0.0 */ export type Tree = { readonly value: A; readonly forest: Forest; }; /** * AnyTree is useful as an extends constraint on a generic type. * * @since 2.0.0 */ export type AnyTree = Tree; /** * TypeOf is a type extractor that returns the inner type A of a Tree. * * @since 2.0.0 */ export type TypeOf = T extends Tree ? A : never; /** * KindTree is the Kind implementation for a Tree. * * @since 2.0.0 */ export interface KindTree extends Kind { readonly kind: Tree>; } /** * This is a constructor function, taking a single value A and optionally an * array of Tree and returning a Tree. * * @since 2.0.0 */ export declare function tree(value: A, forest?: Forest): Tree; /** * The wrap function for Wrappable. * * @since 2.0.0 */ export declare function wrap(value: A, forest?: Forest): Tree; /** * The map function for Mappable. * * @since 2.0.0 */ export declare function map(fai: (a: A) => I): (ta: Tree) => Tree; /** * The flatmap function for Flatmappable. * * @since 2.0.0 */ export declare function flatmap(fati: (a: A) => Tree): (ta: Tree) => Tree; /** * The apply function for Applicable. * * @since 2.0.0 */ export declare function apply(ua: Tree): (tfai: Tree<(a: A) => I>) => Tree; /** * The fold function for Foldable. * * @since 2.0.0 */ export declare function fold(foao: (o: O, a: A) => O, o: O): (ta: Tree) => O; /** * The traverse function for Traversable. * * @since 2.0.0 */ export declare function traverse(V: Applicable): (favi: (a: A) => $) => (ta: Tree) => $, J, K], [L], [M]>; /** * The unwrap function for Unwrappable * * @since 2.0.0 */ export declare function unwrap({ value }: Tree): A; /** * Converts a Forest into a tree representation. * * @since 2.0.0 */ export declare function drawForest(forest: Forest): string; /** * Converts a Tree into a tree representation. * * @since 2.0.0 */ export declare function drawTree(tree: Tree): string; /** * The match function is a recursive fold that collapses a Tree into a single * value I. It does this from the head of the Tree first. * * @since 2.0.0 */ export declare function match(fai: (a: A, is: Array) => I): (ta: Tree) => I; /** * Create an instance of Comparable> from an instance of Comparable. * * @since 2.0.0 */ export declare function getComparableTree({ compare }: Comparable): Comparable>; /** * Get an instance of Showable> from an instance of Showable. * * @since 2.0.0 */ export declare function getShowable({ show }: Showable): Showable>; /** * @since 2.0.0 */ export declare const ApplicableTree: Applicable; /** * @since 2.0.0 */ export declare const FlatmappableTree: Flatmappable; /** * @since 2.0.0 */ export declare const FoldableTree: Foldable; /** * @since 2.0.0 */ export declare const MappableTree: Mappable; /** * @since 2.0.0 */ export declare const TraversableTree: Traversable; /** * @since 2.0.0 */ export declare const WrappableTree: Wrappable; /** * @since 2.0.0 */ export declare const tap: (fn: (value: A) => void) => (ua: Tree) => Tree; /** * @since 2.0.0 */ export declare const bind: (name: Exclude, faui: (a: A) => Tree) => (ua: Tree) => Tree<{ readonly [K_1 in N | keyof A]: K_1 extends keyof A ? A[K_1] : I; }>; /** * @since 2.0.0 */ export declare const bindTo: (name: N) => (ua: Tree) => Tree<{ readonly [K in N]: A; }>;