Evaluates a condition and returns the consequent in an Option.
Option
Condition to evaluate.
Callback used when the condition is true.
Some of the callback result when true, or None when false.
Some
None
import { iff } from '@pacote/iff'import { Some } from '@pacote/option'iff(true, () => 1, () => 0) // => 1iff(false, () => 1) // => Noneiff(false, () => 1, () => 0) // => 0iff(true, () => Some(1)) // => Some(1)// iff(true, () => 1, () => 'zero') // TypeScript error: branch types differ Copy
import { iff } from '@pacote/iff'import { Some } from '@pacote/option'iff(true, () => 1, () => 0) // => 1iff(false, () => 1) // => Noneiff(false, () => 1, () => 0) // => 0iff(true, () => Some(1)) // => Some(1)// iff(true, () => 1, () => 'zero') // TypeScript error: branch types differ
Evaluates a condition and calls the matching branch.
Callback used when the condition is false.
The result returned by the selected callback.
Evaluates a condition and returns the consequent in an
Option.