1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var ap =
|
6 | /*#__PURE__*/
|
7 | require("./ap");
|
8 |
|
9 | var map =
|
10 | /*#__PURE__*/
|
11 | require("./map");
|
12 |
|
13 | var prepend =
|
14 | /*#__PURE__*/
|
15 | require("./prepend");
|
16 |
|
17 | var reduceRight =
|
18 | /*#__PURE__*/
|
19 | require("./reduceRight");
|
20 | /**
|
21 | * Transforms a [Traversable](https://github.com/fantasyland/fantasy-land#traversable)
|
22 | * of [Applicative](https://github.com/fantasyland/fantasy-land#applicative) into an
|
23 | * Applicative of Traversable.
|
24 | *
|
25 | * Dispatches to the `sequence` method of the second argument, if present.
|
26 | *
|
27 | * @func
|
28 | * @memberOf R
|
29 | * @since v0.19.0
|
30 | * @category List
|
31 | * @sig (Applicative f, Traversable t) => (a -> f a) -> t (f a) -> f (t a)
|
32 | * @param {Function} of
|
33 | * @param {*} traversable
|
34 | * @return {*}
|
35 | * @see R.traverse
|
36 | * @example
|
37 | *
|
38 | * R.sequence(Maybe.of, [Just(1), Just(2), Just(3)]); //=> Just([1, 2, 3])
|
39 | * R.sequence(Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()
|
40 | *
|
41 | * R.sequence(R.of, Just([1, 2, 3])); //=> [Just(1), Just(2), Just(3)]
|
42 | * R.sequence(R.of, Nothing()); //=> [Nothing()]
|
43 | */
|
44 |
|
45 |
|
46 | var sequence =
|
47 | /*#__PURE__*/
|
48 | _curry2(function sequence(of, traversable) {
|
49 | return typeof traversable.sequence === 'function' ? traversable.sequence(of) : reduceRight(function (x, acc) {
|
50 | return ap(map(prepend, x), acc);
|
51 | }, of([]), traversable);
|
52 | });
|
53 |
|
54 | module.exports = sequence; |
\ | No newline at end of file |