3.0.4 • Published 9 months ago
@pacote/iff v3.0.4
@pacote/iff
Conditional expressions with Option support.
Installation
yarn add @pacote/iffUsage
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) // => Noneiff(predicate: boolean, onConsequent: () => T, onAlternative?: () => T): T
iff() 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.
See also
License
MIT © Luís Rodrigues.
3.0.4
9 months ago
3.0.3
1 year ago
3.0.2
2 years ago
3.0.1
3 years ago
3.0.0
3 years ago
2.0.9
3 years ago
2.0.8
4 years ago
2.0.7
5 years ago
2.0.6
5 years ago
2.0.5
5 years ago
2.0.4
5 years ago
2.0.3
5 years ago
2.0.2
5 years ago
2.0.1
5 years ago
2.0.0
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago