34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
import _curry3 from './internal/_curry3';
|
|
import map from './map';
|
|
import sequence from './sequence';
|
|
|
|
/**
|
|
* Maps an [Applicative](https://github.com/fantasyland/fantasy-land#applicative)-returning
|
|
* function over a [Traversable](https://github.com/fantasyland/fantasy-land#traversable),
|
|
* then uses [`sequence`](#sequence) to transform the resulting Traversable of Applicative
|
|
* into an Applicative of Traversable.
|
|
*
|
|
* Dispatches to the `traverse` method of the third argument, if present.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.19.0
|
|
* @category List
|
|
* @sig (Applicative f, Traversable t) => (a -> f a) -> (a -> f b) -> t a -> f (t b)
|
|
* @param {Function} of
|
|
* @param {Function} f
|
|
* @param {*} traversable
|
|
* @return {*}
|
|
* @see R.sequence
|
|
* @example
|
|
*
|
|
* // Returns `Nothing` if the given divisor is `0`
|
|
* safeDiv = n => d => d === 0 ? Nothing() : Just(n / d)
|
|
*
|
|
* R.traverse(Maybe.of, safeDiv(10), [2, 4, 5]); //=> Just([5, 2.5, 2])
|
|
* R.traverse(Maybe.of, safeDiv(10), [2, 0, 5]); //=> Nothing
|
|
*/
|
|
var traverse = /*#__PURE__*/_curry3(function traverse(of, f, traversable) {
|
|
return typeof traversable['fantasy-land/traverse'] === 'function' ? traversable['fantasy-land/traverse'](f, of) : sequence(of, map(f, traversable));
|
|
});
|
|
export default traverse; |