Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

when

v0.26.1arrow_drop_down
v0.26.1
STATUS
Passing
DOWNLOADS
11
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 months ago
SIZE
927 B
subject
Tests the final argument by passing it to the given predicate function.
1 contributor
Use when in your project ?
Copied
npm i @bit/ramda.ramda.when
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
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';
revert changes
reload
toggle layout
maximize
truncate("0123456789ABC");
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`.