boolean overview

Added in v2.2.0


Table of contents


destructors

fold

Defines the fold over a boolean value. Takes two thunks onTrue, onFalse and a boolean value. If value is false, onFalse() is returned, otherwise onTrue().

Signature

export declare function fold<A>(onFalse: Lazy<A>, onTrue: Lazy<A>): (value: boolean) => A

Example

import { some, map } from 'fp-ts/lib/Option'
import { pipe } from 'fp-ts/lib/function'
import { fold } from 'fp-ts/lib/boolean'

assert.deepStrictEqual(
  pipe(
    some(true),
    map(
      fold(
        () => 'false',
        () => 'true'
      )
    )
  ),
  some('true')
)

Added in v2.2.0