Skip to content

B (Boolean)

All three dual Boolean operations appear with both shapes in the complete dual-call catalogue.

not_(a: boolean): boolean
and_(a: boolean, b: boolean): boolean
and_(b: boolean): (a: boolean) => boolean
or_(a: boolean, b: boolean): boolean
or_(b: boolean): (a: boolean) => boolean
ifElse<A>(cond: boolean, onTrue: () => A, onFalse: () => A): A
ifElse<A>(onTrue: () => A, onFalse: () => A): (cond: boolean) => A

Trailing underscores avoid colliding with JS reserved words.

import { pipe } from '@stopcock/fp'
import * as B from '@stopcock/fp/boolean'
pipe(true, B.not_) // false
B.and_(true, false) // false, direct data-first
pipe(true, B.and_(false)) // false, curried data-last
pipe(
false,
B.ifElse(
() => 'yes',
() => 'no',
),
) // 'no'
// toggle a feature flag
const toggled = pipe(isEnabled, B.not_)
// both conditions must hold
const canAccess = pipe(isAdmin, B.and_(isActive))