Overview

Multi-way trees (aka rose trees) and forests, where a forest is

type Forest<A> = Array<Tree<A>>

Table of contents


Tree (interface)

Signature

export interface Tree<A> {
  readonly value: A
  readonly forest: Forest<A>
}

Added in v2.0.0

Forest (type alias)

Signature

export type Forest<A> = Array<Tree<A>>

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0

URI (constant)

Signature

export const URI: "Tree" = ...

Added in v2.0.0

tree (constant)

Signature

export const tree: Monad1<URI> & Foldable1<URI> & Traversable1<URI> & Comonad1<URI> = ...

Added in v2.0.0

drawForest (function)

Neat 2-dimensional drawing of a forest

Signature

export function drawForest(forest: Forest<string>): string { ... }

Added in v2.0.0

drawTree (function)

Neat 2-dimensional drawing of a tree

Signature

export function drawTree(tree: Tree<string>): string { ... }

Example

import { make, drawTree, tree } from 'fp-ts/lib/Tree'

const fa = make('a', [tree.of('b'), tree.of('c'), make('d', [tree.of('e'), tree.of('f')])])

assert.strictEqual(
  drawTree(fa),
  `a
├─ b
├─ c
└─ d
   ├─ e
   └─ f`
)

Added in v2.0.0

elem (function)

Signature

export function elem<A>(E: Eq<A>): (a: A, fa: Tree<A>) => boolean { ... }

Added in v2.0.0

getEq (function)

Signature

export function getEq<A>(E: Eq<A>): Eq<Tree<A>> { ... }

Added in v2.0.0

getShow (function)

Signature

export function getShow<A>(S: Show<A>): Show<Tree<A>> { ... }

Added in v2.0.0

make (function)

Signature

export function make<A>(value: A, forest: Forest<A> = empty): Tree<A> { ... }

Added in v2.0.0

unfoldForest (function)

Build a tree from a seed value

Signature

export function unfoldForest<A, B>(bs: Array<B>, f: (b: B) => [A, Array<B>]): Forest<A> { ... }

Added in v2.0.0

unfoldForestM (function)

Monadic forest builder, in depth-first order

Signature

export function unfoldForestM<M extends URIS3>(
  M: Monad3<M>
): <R, E, A, B>(bs: Array<B>, f: (b: B) => Kind3<M, R, E, [A, Array<B>]>) => Kind3<M, R, E, Forest<A>>
export function unfoldForestM<M extends URIS2>(
  M: Monad2<M>
): <R, E, B>(bs: Array<B>, f: (b: B) => Kind2<M, R, [E, Array<B>]>) => Kind2<M, R, Forest<E>>
export function unfoldForestM<M extends URIS2, E>(
  M: Monad2C<M, E>
): <A, B>(bs: Array<B>, f: (b: B) => Kind2<M, E, [A, Array<B>]>) => Kind2<M, E, Forest<A>>
export function unfoldForestM<M extends URIS>(
  M: Monad1<M>
): <A, B>(bs: Array<B>, f: (b: B) => Kind<M, [A, Array<B>]>) => Kind<M, Forest<A>>
export function unfoldForestM<M>(
  M: Monad<M>
): <A, B>(bs: Array<B>, f: (b: B) => HKT<M, [A, Array<B>]>) => HKT<M, Forest<A>> { ... }

Added in v2.0.0

unfoldTree (function)

Build a tree from a seed value

Signature

export function unfoldTree<A, B>(b: B, f: (b: B) => [A, Array<B>]): Tree<A> { ... }

Added in v2.0.0

unfoldTreeM (function)

Monadic tree builder, in depth-first order

Signature

export function unfoldTreeM<M extends URIS3>(
  M: Monad3<M>
): <R, E, A, B>(b: B, f: (b: B) => Kind3<M, R, E, [A, Array<B>]>) => Kind3<M, R, E, Tree<A>>
export function unfoldTreeM<M extends URIS2>(
  M: Monad2<M>
): <E, A, B>(b: B, f: (b: B) => Kind2<M, E, [A, Array<B>]>) => Kind2<M, E, Tree<A>>
export function unfoldTreeM<M extends URIS2, E>(
  M: Monad2C<M, E>
): <A, B>(b: B, f: (b: B) => Kind2<M, E, [A, Array<B>]>) => Kind2<M, E, Tree<A>>
export function unfoldTreeM<M extends URIS>(
  M: Monad1<M>
): <A, B>(b: B, f: (b: B) => Kind<M, [A, Array<B>]>) => Kind<M, Tree<A>>
export function unfoldTreeM<M>(M: Monad<M>): <A, B>(b: B, f: (b: B) => HKT<M, [A, Array<B>]>) => HKT<M, Tree<A>> { ... }

Added in v2.0.0

ap (export)

Signature

<A>(fa: Tree<A>) => <B>(fab: Tree<(a: A) => B>) => Tree<B>

Added in v2.0.0

apFirst (export)

Signature

<B>(fb: Tree<B>) => <A>(fa: Tree<A>) => Tree<A>

Added in v2.0.0

apSecond (export)

Signature

<B>(fb: Tree<B>) => <A>(fa: Tree<A>) => Tree<B>

Added in v2.0.0

chain (export)

Signature

<A, B>(f: (a: A) => Tree<B>) => (ma: Tree<A>) => Tree<B>

Added in v2.0.0

chainFirst (export)

Signature

<A, B>(f: (a: A) => Tree<B>) => (ma: Tree<A>) => Tree<A>

Added in v2.0.0

duplicate (export)

Signature

<A>(ma: Tree<A>) => Tree<Tree<A>>

Added in v2.0.0

extend (export)

Signature

<A, B>(f: (fa: Tree<A>) => B) => (ma: Tree<A>) => Tree<B>

Added in v2.0.0

flatten (export)

Signature

<A>(mma: Tree<Tree<A>>) => Tree<A>

Added in v2.0.0

foldMap (export)

Signature

;<M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (fa: Tree<A>) => M

Added in v2.0.0

map (export)

Signature

<A, B>(f: (a: A) => B) => (fa: Tree<A>) => Tree<B>

Added in v2.0.0

reduce (export)

Signature

;<A, B>(b: B, f: (b: B, a: A) => B) => (fa: Tree<A>) => B

Added in v2.0.0

reduceRight (export)

Signature

;<A, B>(b: B, f: (a: A, b: B) => B) => (fa: Tree<A>) => B

Added in v2.0.0