1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var ap =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./ap.js");
|
---|
8 |
|
---|
9 | var map =
|
---|
10 | /*#__PURE__*/
|
---|
11 | require("./map.js");
|
---|
12 |
|
---|
13 | var prepend =
|
---|
14 | /*#__PURE__*/
|
---|
15 | require("./prepend.js");
|
---|
16 |
|
---|
17 | var reduceRight =
|
---|
18 | /*#__PURE__*/
|
---|
19 | require("./reduceRight.js");
|
---|
20 |
|
---|
21 | var identity =
|
---|
22 | /*#__PURE__*/
|
---|
23 | require("./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 |
|
---|
52 | var 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 |
|
---|
64 | module.exports = sequence; |
---|