← Back

Source

tree

Monad1<URI> & Foldable2v1<URI> & Traversable2v1<URI> & Comonad1<URI>

Added in v1.6.0 (instance)

Tree

constructor(readonly value: A, readonly forest: Forest<A>) {}

Added in v1.6.0 (data)

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

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

ap

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

Added in v1.6.0 (method)

ap_

<B, C>(this: Tree<(b: B) => C>, fb: Tree<B>): Tree<C>

Added in v1.6.0 (method)

Flipped version of ap

chain

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

Added in v1.6.0 (method)

extend

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

Added in v1.6.0 (method)

extract

(): A

Added in v1.6.0 (method)

inspect

(): string

Added in v1.6.0 (method)

map

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

Added in v1.6.0 (method)

reduce

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

Added in v1.6.0 (method)

toString

(): string

Added in v1.6.0 (method)

drawForest

(forest: Forest<string>): string

Added in v1.6.0 (function)

Neat 2-dimensional drawing of a forest

drawTree

(tree: Tree<string>): string

Added in v1.6.0 (function)

Neat 2-dimensional drawing of a tree

Example

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

const fa = new Tree('a', [new Tree('b', []), new Tree('c', []), new Tree('d', [new Tree('e', []), new Tree('f', [])])])

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

getSetoid

<A>(S: Setoid<A>): Setoid<Tree<A>>

Added in v1.6.0 (function)

unfoldForest

<A, B>(bs: Array<B>, f: (b: B) => [A, Array<B>]): Forest<A>

Added in v1.6.0 (function)

Build a tree from a seed value

unfoldForestM

unfoldForestM<M>(
  M: Monad<M>
): <A, B>(bs: Array<B>, f: (b: B) => HKT<M, [A, Array<B>]>) => HKT<M, Forest<A>>

Added in v1.6.0 (function)

Monadic forest builder, in depth-first order

unfoldTree

<A, B>(b: B, f: (b: B) => [A, Array<B>]): Tree<A>

Added in v1.6.0 (function)

Build a tree from a seed value

unfoldTreeM

unfoldTreeM<M>(M: Monad<M>): <A, B>(b: B, f: (b: B) => HKT<M, [A, Array<B>]>) => HKT<M, Tree<A>>

Added in v1.6.0 (function)

Monadic tree builder, in depth-first order