cond

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
3 KB
Returns a function, `fn`, which encapsulates `if/else, if/else, ...` logic.
1 contributor
Install cond as a package?
Copied
npm i @bit/justin-capalbo.ramda.cond
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
cond (
pairs:Array
) : Function

Returns a function, fn, which encapsulates if/else, if/else, ... logic. R.cond takes a list of [predicate, transformer] pairs. All of the arguments to fn are applied to each of the predicates in turn until one returns a “truthy” value, at which point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates matches, fn returns undefined.

Example
const fn = R.cond([
       [R.equals(0),   R.always('water freezes at 0°C')],
       [R.equals(100), R.always('water boils at 100°C')],
       [R.T,           temp => 'nothing special happens at ' + temp + '°C']
     ]);
     fn(0); //=> 'water freezes at 0°C'
     fn(50); //=> 'nothing special happens at 50°C'
     fn(100); //=> 'water boils at 100°C'
Argument
pairs: Array

A list of [predicate, transformer]

Returns
Function

Help and resources