Skip to content

Latest commit

 

History

History
113 lines (74 loc) · 2.49 KB

Unfoldable.md

File metadata and controls

113 lines (74 loc) · 2.49 KB
id title
Unfoldable
Module Unfoldable

← Index

Source

Unfoldable

Signature (type class) Source

export interface Unfoldable<F> {
  readonly URI: F
  readonly unfoldr: <A, B>(b: B, f: (b: B) => Option<[A, B]>) => HKT<F, A>
}

This class identifies data structures which can be unfolded, generalizing unfoldr on arrays.

Added in v1.0.0

empty

The container with no elements - unfolded with zero iterations.

Signature (function) Source

export function empty<F, A>(U: Unfoldable<F>): HKT<F, A>  { ... }

Example

import { empty } from 'fp-ts/lib/Unfoldable'
import { array } from 'fp-ts/lib/Array'

assert.deepStrictEqual(empty(array), [])

Added in v1.0.0

replicate

Replicate a value some natural number of times.

Signature (function) Source

export function replicate<F>(U: Unfoldable<F>): <A>(a: A, n: number) => HKT<F, A>  { ... }

Example

import { replicate } from 'fp-ts/lib/Unfoldable'
import { array } from 'fp-ts/lib/Array'

assert.deepStrictEqual(replicate(array)('s', 2), ['s', 's'])

Added in v1.0.0

replicateA

Perform an Applicative action n times, and accumulate all the results

Signature (function) Source

export function replicateA<F, T>(
  F: Applicative<F>,
  // tslint:disable-next-line: deprecation
  UT: Unfoldable<T> & Traversable<T>
): <A>(n: number, ma: HKT<F, A>) => HKT<F, HKT<T, A>>  { ... }

Example

import { replicateA } from 'fp-ts/lib/Unfoldable'
import { array } from 'fp-ts/lib/Array'
import { option, some, none } from 'fp-ts/lib/Option'

assert.deepStrictEqual(replicateA(option, array)(2, some(1)), some([1, 1]))
assert.deepStrictEqual(replicateA(option, array)(2, none), none)

Added in v1.0.0

singleton

Contain a single value

Signature (function) Source

export function singleton<F>(U: Unfoldable<F>): <A>(a: A) => HKT<F, A>  { ... }

Example

import { singleton } from 'fp-ts/lib/Unfoldable'
import { array } from 'fp-ts/lib/Array'

assert.deepStrictEqual(singleton(array)(1), [1])

Added in v1.0.0