main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
894 bytes
|
Line | |
---|
1 | import { curry } from 'ramda';
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Returns the second argument if predicate function returns `true`,
|
---|
5 | * otherwise the third argument is returned.
|
---|
6 | *
|
---|
7 | * @func defaultWhen
|
---|
8 | * @memberOf RA
|
---|
9 | * @since {@link https://char0n.github.io/ramda-adjunct/2.2.0|v2.2.0}
|
---|
10 | * @category Logic
|
---|
11 | * @sig (a -> Boolean) -> b -> a -> a | b
|
---|
12 | * @param {!function} predicate The predicate function
|
---|
13 | * @param {*} defaultVal The default value
|
---|
14 | * @param {*} val `val` will be returned instead of `defaultVal` if predicate returns false
|
---|
15 | * @return {*} The `val` if predicate returns `false`, otherwise the default value
|
---|
16 | * @see {@link http://ramdajs.com/docs/#defaultTo|R.defaultTo}
|
---|
17 | * @example
|
---|
18 | *
|
---|
19 | * RA.defaultWhen(RA.isNull, 1, null); // => 1
|
---|
20 | * RA.defaultWhen(RA.isNull, 1, 2); // => 2
|
---|
21 | */
|
---|
22 | const defaultWhen = curry((predicate, defaultVal, val) =>
|
---|
23 | predicate(val) ? defaultVal : val
|
---|
24 | );
|
---|
25 |
|
---|
26 | export default defaultWhen;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.