when

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
923 B
Tests the final argument by passing it to the given predicate function.
1 contributor
Install when as a package?
Copied
npm i @bit/justin-capalbo.ramda.when
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
when (
pred:Function,
whenTrueFn:Function,
x:*
) : *

Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function will return the result of calling the whenTrueFn function with the same argument. If the predicate is not satisfied, the argument is returned as is.

Example
// truncate :: String -> String
     const truncate = R.when(
       R.propSatisfies(R.gt(R.__, 10), 'length'),
       R.pipe(R.take(10), R.append('…'), R.join(''))
     );
     truncate('12345');         //=> '12345'
     truncate('0123456789ABC'); //=> '0123456789…'
Arguments
pred: Function

A predicate function

whenTrueFn: Function

A function to invoke when the condition evaluates to a truthy value.

x: *

An object to test with the pred function and pass to whenTrueFn if necessary.

Returns
*

Either `x` or the result of applying `x` to `whenTrueFn`.

Help and resources