source: node_modules/ramda/src/sequence.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var ap =
6/*#__PURE__*/
7require("./ap.js");
8
9var map =
10/*#__PURE__*/
11require("./map.js");
12
13var prepend =
14/*#__PURE__*/
15require("./prepend.js");
16
17var reduceRight =
18/*#__PURE__*/
19require("./reduceRight.js");
20
21var identity =
22/*#__PURE__*/
23require("./internal/_identity.js");
24/**
25 * Transforms a [Traversable](https://github.com/fantasyland/fantasy-land#traversable)
26 * of [Applicative](https://github.com/fantasyland/fantasy-land#applicative) into an
27 * Applicative of Traversable.
28 *
29 * Dispatches to the `"fantasy-land/traverse"` or the `traverse` method of the second argument, if present.
30 *
31 * @func
32 * @memberOf R
33 * @since v0.19.0
34 * @category List
35 * @sig fantasy-land/of :: TypeRep f => f ~> a -> f a
36 * @sig (Applicative f, Traversable t) => TypeRep f -> t (f a) -> f (t a)
37 * @sig (Applicative f, Traversable t) => (a -> f a) -> t (f a) -> f (t a)
38 * @param {Object|Function} TypeRepresentative with an `of` or `fantasy-land/of` method
39 * @param {*} traversable
40 * @return {*}
41 * @see R.traverse
42 * @example
43 *
44 * R.sequence(Maybe.of, [Just(1), Just(2), Just(3)]); //=> Just([1, 2, 3])
45 * R.sequence(Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()
46 *
47 * R.sequence(R.of(Array), Just([1, 2, 3])); //=> [Just(1), Just(2), Just(3)]
48 * R.sequence(R.of(Array), Nothing()); //=> [Nothing()]
49 */
50
51
52var sequence =
53/*#__PURE__*/
54_curry2(function sequence(F, traversable) {
55 var of = typeof F['fantasy-land/of'] === 'function' ? F['fantasy-land/of'] : typeof F.of === 'function' ? F.of : F;
56 var TypeRep = {
57 'fantasy-land/of': of
58 };
59 return typeof traversable['fantasy-land/traverse'] === 'function' ? traversable['fantasy-land/traverse'](TypeRep, identity) : typeof traversable.traverse === 'function' ? traversable.traverse(TypeRep, identity) : reduceRight(function (x, acc) {
60 return ap(map(prepend, x), acc);
61 }, of([]), traversable);
62});
63
64module.exports = sequence;
Note: See TracBrowser for help on using the repository browser.