Conditional expressions with Option support.
yarn add @pacote/iff
import { iff } from '@pacote/iff'
iff(
true,
() => 1,
() => 0
) // => 1
iff(
false,
() => 1,
() => 0
) // => 0
iff(
true,
() => 1,
() => 'zero'
) // type error, branches are not the same type
iff(true, () => 1) // => Some(1)
iff(false, () => 1) // => None
iff(predicate: boolean, onConsequent: () => T, onAlternative?: () => T): Tiff() evaluates a predicate and returns the result of calling
onConsequent() if the predicate is true or the result of onAlternative()
if the predicate is false.
onConsequent and onAlternative must be functions with the same return type.
iff(predicate: boolean, onConsequent: () => T): Option<T>If onAlternative is not provided or is nullable, iff() will always return
an Option<T> data type: Some<T> if the predicate is true, or None if the
predicate is false.
MIT © Luís Rodrigues.