1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _ramda = require("ramda");
|
---|
6 | var _Identity = _interopRequireDefault(require("./fantasy-land/Identity"));
|
---|
7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
8 | /**
|
---|
9 | * Creates a [Traversable](https://github.com/fantasyland/fantasy-land#traversable) lens
|
---|
10 | * from an [Applicative](https://github.com/fantasyland/fantasy-land#applicative)-returning function.
|
---|
11 | *
|
---|
12 | * When executed, it maps an [Applicative](https://github.com/fantasyland/fantasy-land#applicative)-returning
|
---|
13 | * function over a [Traversable](https://github.com/fantasyland/fantasy-land#traversable),
|
---|
14 | * then uses [`sequence`](https://ramdajs.com/docs/#sequence) to transform the resulting Traversable of Applicative
|
---|
15 | * into an Applicative of Traversable.
|
---|
16 | *
|
---|
17 | * Dispatches to the `traverse` method of the third argument, if present.
|
---|
18 | *
|
---|
19 | * @func lensTraverse
|
---|
20 | * @memberOf RA
|
---|
21 | * @since {@link https://char0n.github.io/ramda-adjunct/2.7.0|2.7.0}
|
---|
22 | * @category Relation
|
---|
23 | * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
|
---|
24 | * @sig fantasy-land/of :: TypeRep f => f ~> a → f a
|
---|
25 | * @sig Applicative f => (a -> f a) -> Lens s a
|
---|
26 | * @sig Applicative f => TypeRep f -> Lens s a
|
---|
27 | * @param {!Object|!Function} TypeRepresentative with an `of` or `fantasy-land/of` method
|
---|
28 | * @return {!function} The Traversable lens
|
---|
29 | * @see {@link http://ramdajs.com/docs/#lens|R.lens}, {@link http://ramdajs.com/docs/#traverse|R.traverse}
|
---|
30 | *
|
---|
31 | * @example
|
---|
32 | *
|
---|
33 | * const maybeLens = RA.lensTraverse(Maybe.of);
|
---|
34 | * const safeDiv = n => d => d === 0 ? Maybe.Nothing() : Maybe.Just(n / d)
|
---|
35 | *
|
---|
36 | * R.over(maybeLens, safeDiv(10), [2, 4, 5]); // => Just([5, 2.5, 2])
|
---|
37 | * R.over(maybeLens, safeDiv(10), [2, 0, 5]); // => Nothing
|
---|
38 | *
|
---|
39 | * R.view(maybeLens, [Maybe.Just(2), Maybe.Just(3)]); // => Maybe.Just([2, 3])
|
---|
40 | *
|
---|
41 | * R.set(maybeLens, Maybe.Just(1), [Maybe.just(2), Maybe.Just(3)]); // => Maybe.Just([1, 1])
|
---|
42 | */
|
---|
43 | /* eslint-disable no-nested-ternary */
|
---|
44 | var lensTraverse = (0, _ramda.curryN)(1, function (F) {
|
---|
45 | var of = typeof F['fantasy-land/of'] === 'function' ? F['fantasy-land/of'] : typeof F.of === 'function' ? F.of : F;
|
---|
46 | var TypeRep = {
|
---|
47 | 'fantasy-land/of': of
|
---|
48 | };
|
---|
49 | return (0, _ramda.curry)(function (toFunctorFn, target) {
|
---|
50 | return _Identity["default"].of((0, _ramda.traverse)(TypeRep, (0, _ramda.pipe)(toFunctorFn, (0, _ramda.prop)('value')), target));
|
---|
51 | });
|
---|
52 | });
|
---|
53 | /* eslint-enable */
|
---|
54 | var _default = lensTraverse;
|
---|
55 | exports["default"] = _default; |
---|