1 | var _curry3 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry3");
|
4 |
|
5 | var map =
|
6 | /*#__PURE__*/
|
7 | require("./map");
|
8 |
|
9 | var sequence =
|
10 | /*#__PURE__*/
|
11 | require("./sequence");
|
12 | /**
|
13 | * Maps an [Applicative](https://github.com/fantasyland/fantasy-land#applicative)-returning
|
14 | * function over a [Traversable](https://github.com/fantasyland/fantasy-land#traversable),
|
15 | * then uses [`sequence`](#sequence) to transform the resulting Traversable of Applicative
|
16 | * into an Applicative of Traversable.
|
17 | *
|
18 | * Dispatches to the `traverse` method of the third argument, if present.
|
19 | *
|
20 | * @func
|
21 | * @memberOf R
|
22 | * @since v0.19.0
|
23 | * @category List
|
24 | * @sig (Applicative f, Traversable t) => (a -> f a) -> (a -> f b) -> t a -> f (t b)
|
25 | * @param {Function} of
|
26 | * @param {Function} f
|
27 | * @param {*} traversable
|
28 | * @return {*}
|
29 | * @see R.sequence
|
30 | * @example
|
31 | *
|
32 | * // Returns `Maybe.Nothing` if the given divisor is `0`
|
33 | * const safeDiv = n => d => d === 0 ? Maybe.Nothing() : Maybe.Just(n / d)
|
34 | *
|
35 | * R.traverse(Maybe.of, safeDiv(10), [2, 4, 5]); //=> Maybe.Just([5, 2.5, 2])
|
36 | * R.traverse(Maybe.of, safeDiv(10), [2, 0, 5]); //=> Maybe.Nothing
|
37 | */
|
38 |
|
39 |
|
40 | var traverse =
|
41 | /*#__PURE__*/
|
42 | _curry3(function traverse(of, f, traversable) {
|
43 | return typeof traversable['fantasy-land/traverse'] === 'function' ? traversable['fantasy-land/traverse'](f, of) : sequence(of, map(f, traversable));
|
44 | });
|
45 |
|
46 | module.exports = traverse; |
\ | No newline at end of file |