source: node_modules/ramda/es/sequence.js

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

Initial commit

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