import * as fc from 'fast-check'; import * as M from 'monocle-ts'; import * as Foldable from 'fp-ts/Foldable'; import { Predicate } from 'fp-ts/function'; import * as NEA from 'fp-ts/lib/NonEmptyArray'; import * as O from 'fp-ts/lib/Option'; import * as TE from 'fp-ts/lib/TaskEither'; import * as Traversable from 'fp-ts/Traversable'; import * as T from 'fp-ts/Tree'; import { Named } from '@monorail/sharedHelpers/names'; export * from 'fp-ts/lib/Tree'; export { forestInstances as forest }; declare const ForestURI = "Forest"; declare type ForestURI = typeof ForestURI; declare module 'fp-ts/HKT' { interface URItoKind { readonly [ForestURI]: T.Forest; } } declare const forestInstances: Foldable.Foldable1 & Traversable.Traversable1; export declare const mapForest: (f: (a: A) => B) => (fa: T.Forest) => T.Forest, reduceForest: (b: B, f: (b: B, a: A) => B) => (fa: T.Forest) => B, reduceRightForest: (b: B, f: (a: A, b: B) => B) => (fa: T.Forest) => B, foldMapForest: (M: import("fp-ts/lib/Monoid").Monoid) => (f: (a: A) => M) => (fa: T.Forest) => M; export declare const getForestTraversal: () => M.Traversal, A>; export declare const getForestFold: () => M.Fold, A>; export declare function getForestOptionalFromPath(path: NEA.NonEmptyArray): M.Optional, T.Forest>; export declare function getTreeOptionalFromPath(path: NEA.NonEmptyArray): M.Optional, T.Tree>; export declare const fromForestPath: (f: T.Forest) => (p: NodePath) => O.Option>; /** * Constructs an instance of `Abritrary>` given an `Arbitrary` and a `maxDepth` */ export declare function getArbitrary(arb: fc.Arbitrary, opts?: { maxDepth?: number; maxWidth?: number; }): fc.Arbitrary>; /** * Splices trees in a forest that match a predicate. `mapMatch` returns a * `Forest` that will be flattened into the match's parent forest, so you can * add or remove nodes at the matched level. */ export declare const spliceWhere: (predicate: Predicate>) => (mapMatch: (a: T.Tree) => T.Forest, mapNotMatch?: (a: T.Tree) => T.Tree) => (forest: T.Forest) => T.Forest; /** * Splices trees in a forest that match a predicate, asynchronously. `mapMatch` * returns a `Task>` that will be flattened into the match's parent * forest, so you can add or remove nodes at the matched level. */ export declare const spliceWhereAsync: (predicate: Predicate>) => (mapMatch: (a: T.Tree) => TE.TaskEither>, mapNotMatch?: (a: T.Tree) => TE.TaskEither>) => (forest: T.Forest) => TE.TaskEither>; /** * Duplicates all trees in a forest that match `predicate`. Does _not_ copy * children. */ export declare const duplicateWhere: (predicate: Predicate>) => (modify?: (a: A) => A) => (forest: T.Forest) => T.Forest; /** * Duplicates all trees in a forest that match `predicate`, asynchronously. Does * _not_ copy children. */ export declare const duplicateWhereAsync: (predicate: Predicate>) => (modify: (a: A) => TE.TaskEither) => (forest: T.Forest) => TE.TaskEither>; /** * Removes all trees in a forest that match `predicate`. */ export declare const removeWhere: (predicate: Predicate>) => (forest: T.Forest) => T.Forest; /** * Adds a child to all trees in a forest that match `predicate`. */ export declare const addChildWhere: (predicate: Predicate>) => (createChild: (a: T.Tree) => T.Tree) => (forest: T.Forest) => T.Forest; /** * Adds a child to all trees in a forest that match `predicate`, asynchronously */ export declare const addChildWhereAsync: (predicate: Predicate>) => (createChild: (a: T.Tree) => TE.TaskEither>) => (forest: T.Forest) => TE.TaskEither>; export declare const addRoot: (root: A) => (forest: T.Forest) => T.Forest; /** * A NodePath represents a path from a forest to a particular tree. */ declare type NodePath = NEA.NonEmptyArray; /** * Returns an index-path to the first node in a forest that matches `predicate`, * or `none` if no such node exists. * * A named `NodePath` should always lead to a tree for the associated forest. */ export declare const getPath: (predicate: Predicate>) => (forest: Named, Name>) => O.Option>; /** * Returns the node pointed to by a named path */ export declare const getNode: (forest: Named, Name>) => (path: Named) => A; /** * Changes a path to the position left of a node. */ export declare const getLeft: (path: NodePath) => NodePath; /** * Changes a named path to the position left of a node, if one exists. * * Guaranteed to be either a valid path for the associated forest, or `none`. */ export declare const getValidatedLeft: (path: Named) => O.Option>; /** * Changes a path to the parent of a node, if one exists. */ export declare const getParent: (path: NodePath) => O.Option; /** * Changes a named path to the parent of a node, if one exists. */ export declare const getValidatedParent: (path: Named) => O.Option>; /** * Changes a path to the position right of a node */ export declare const getRight: (path: NodePath) => NodePath; /** * Changes a path to the first child of a node */ export declare const getFirstChild: (path: NodePath) => NodePath; /** * Returns true if the node at path `b` is the same node as or a descendent of * the node at path `a` */ export declare const isEqualOrDescendentOf: (a: Named) => (b: Named) => boolean; export declare const isNodePathDescendantOf: (a: Named) => (b: Named) => boolean; export declare const isNodePathEqual: (a: Named) => (b: Named) => boolean; /** * Moves a node at `from` to `to`. The paths must be created from a named forest. * * @example * const forest = [ * T.make('a', [ * T.make('b', [ * T.make('d'), * ]), * T.make('c'), * ]), * ] * name(forest)(nf => { * const from = getPath(n => n.value === 'b')(nf) * const to = getPath(n => n.value === 'a')(nf) * expect(moveNode(from, to)(nf)).toEqual( * O.some([ * T.make('b', [ * T.make('d'), * ]), * T.make('a', [ * T.make('c'), * ]), * ]), * ) * }) */ export declare const moveNode: (from: Named, to: Named) => (forest: Named, Name>) => O.Option>; /** * Moves a node to the left if possible. * * @example * const forest = [ * T.make('a', [ * T.make('b', [ * T.make('d'), * ]), * T.make('c'), * ]), * ] * expect(moveLeft(n => n.value === 'c')(forest)).toEqual(O.some([ * T.make('a', [ * T.make('c'), * T.make('b', [ * T.make('d'), * ]), * ]), * ])) */ export declare const moveLeft: (predicate: Predicate>) => (forest: T.Forest) => O.Option>; /** * Moves a node to the left of the parent * * @example * const forest = [ * T.make('a', [ * T.make('b', [ * T.make('d'), * ]), * T.make('c'), * ]), * ] * expect(moveUp(n => n.value === 'd')(forest)).toEqual(O.some([ * T.make('a', [ * T.make('d'), * T.make('b'), * T.make('c'), * ]), * ])) */ export declare const moveUpBefore: (predicate: Predicate>) => (forest: T.Forest) => O.Option>; /** * Moves a node to the right of the parent * * @example * const forest = [ * T.make('a', [ * T.make('b', [ * T.make('d'), * ]), * T.make('c'), * ]), * ] * expect(moveUp(n => n.value === 'd')(forest)).toEqual(O.some([ * T.make('a', [ * T.make('b'), * T.make('d'), * T.make('c'), * ]), * ])) */ export declare const moveUpAfter: (predicate: Predicate>) => (forest: T.Forest) => O.Option>; /** * Moves a node to the right if possible. * * @example * const forest = [ * T.make('a', [ * T.make('b', [ * T.make('d'), * ]), * T.make('c'), * ]), * ] * expect(moveDown(n => n.value === 'b')(forest)).toEqual(O.some([ * T.make('a', [ * T.make('c'), * T.make('b', [ * T.make('d'), * ]), * ]), * ])) */ export declare const moveRight: (predicate: Predicate>) => (forest: T.Forest) => O.Option>; /** * Moves a node into the children of the next node, if possible. * * @example * const forest = [ * T.make('a', [ * T.make('b', [ * T.make('d'), * ]), * T.make('c'), * ]), * ] * expect(moveInto(n => n.value === 'b')(forest)).toEqual(O.some([ * T.make('a', [ * T.make('c', [ * T.make('b', [ * T.make('d'), * ]), * ]), * ]), * ])) */ export declare const moveInto: (predicate: Predicate>) => (forest: T.Forest) => O.Option>; /** * Returns true if the first node matching the predicate is the leftmost node of * its forest. */ export declare const isLeftmost: (predicate: Predicate>) => (forest: T.Forest) => boolean; /** * Returns true if the first node matching the predicate has a parent node */ export declare const hasParent: (predicate: Predicate>) => (forest: T.Forest) => boolean; /** * Returns true if the first node matching the predicate is the rightmost node of * its forest. Returns false otherwise, or if no node is found. */ export declare const isRightmost: (predicate: Predicate>) => (forest: T.Forest) => boolean; /** * Gets all parents of the first matching node */ export declare const getAncestorsOf: (predicate: Predicate>) => (forest: T.Forest) => O.Option; export declare const findFirst: (predicate: Predicate) => (forest: T.Forest) => O.Option;