ramda-extension
Version:
Helpful functions built on top of the mighty Ramda
22 lines (21 loc) • 838 B
JavaScript
import { juxt, flip, T, always, useWith, compose, equals, identity, cond } from 'ramda';
import argumentsToList from './argumentsToList';
var equalsAndAlways = /*#__PURE__*/useWith(argumentsToList, [equals, always]);
/**
* Returns the opposite value comparing against a given set of two values.
*
* @func
* @category Function
*
* @param {Array} options - must be array of two items
* @param {*} val
* @return {*} opposite of options
* @example
*
* R_.toggle('on', 'off')('on'); // 'off'
* R_.toggle('active', 'inactive')('inactive'); // 'active'
* R_.toggle(10, 100)(10); // 100
* R_.toggle('on', 'off')('other'); // 'other'
*/
var toggle = /*#__PURE__*/compose(cond, /*#__PURE__*/juxt([equalsAndAlways, /*#__PURE__*/flip(equalsAndAlways), /*#__PURE__*/always([T, identity])]));
export default toggle;