ramda-adjunct
Version:
Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
51 lines (46 loc) • 2.11 kB
JavaScript
exports.__esModule = true;
exports["default"] = void 0;
var _ramda = require("ramda");
var _Identity = _interopRequireDefault(require("./fantasy-land/Identity"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Creates a [Traversable](https://github.com/fantasyland/fantasy-land#traversable) lens
* from an [Applicative](https://github.com/fantasyland/fantasy-land#applicative)-returning function.
*
* When executed, it maps an [Applicative](https://github.com/fantasyland/fantasy-land#applicative)-returning
* function over a [Traversable](https://github.com/fantasyland/fantasy-land#traversable),
* then uses [`sequence`](#sequence) to transform the resulting Traversable of Applicative
* into an Applicative of Traversable.
*
* Dispatches to the `traverse` method of the third argument, if present.
*
* @func lensTraverse
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/2.7.0|2.7.0}
* @category Relation
* @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
* @sig Applicative f => (a -> f a) -> Lens s a
* @param {!function} of The Applicative-returning function
* @return {!function} The Traversable lens
* @see {@link http://ramdajs.com/docs/#lens|R.lens}, {@link http://ramdajs.com/docs/#traverse|R.traverse}
*
* @example
*
* const maybeLens = RA.lensTraverse(Maybe.of);
* const safeDiv = n => d => d === 0 ? Maybe.Nothing() : Maybe.Just(n / d)
*
* R.over(maybeLens, safeDiv(10), [2, 4, 5]); // => Just([5, 2.5, 2])
* R.over(maybeLens, safeDiv(10), [2, 0, 5]); // => Nothing
*
* R.view(maybeLens, [Maybe.Just(2), Maybe.Just(3)]); // => Maybe.Just([2, 3])
*
* R.set(maybeLens, Maybe.Just(1), [Maybe.just(2), Maybe.Just(3)]); // => Maybe.Just([1, 1])
*/
var lensTraverse = (0, _ramda.curryN)(1, function (of) {
return (0, _ramda.curry)(function (toFunctorFn, target) {
return _Identity["default"].of((0, _ramda.traverse)(of, (0, _ramda.pipe)(toFunctorFn, (0, _ramda.prop)('value')), target));
});
});
var _default = lensTraverse;
exports["default"] = _default;
;