3.0.2 • Published 9 months ago
@pacote/iff v3.0.2
@pacote/iff
Conditional expressions with Option support.
Installation
yarn add @pacote/iff
Usage
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): 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.2
9 months ago
3.0.1
1 year ago
3.0.0
1 year ago
2.0.9
1 year ago
2.0.8
3 years ago
2.0.7
3 years ago
2.0.6
3 years ago
2.0.5
3 years ago
2.0.4
3 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.1
3 years ago
2.0.0
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago