forked from ramda/ramda
/
promap.js
37 lines (34 loc) · 1.47 KB
/
promap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import _curry3 from './internal/_curry3.js';
import _dispatchable from './internal/_dispatchable.js';
import _promap from './internal/_promap.js';
import _xpromap from './internal/_xpromap.js';
/**
* Takes two functions as pre- and post- processors respectively for a third function,
* i.e. `promap(f, g, h)(x) === g(h(f(x)))`.
*
* Dispatches to the `promap` method of the third argument, if present,
* according to the [FantasyLand Profunctor spec](https://github.com/fantasyland/fantasy-land#profunctor).
*
* Acts as a transducer if a transformer is given in profunctor position.
*
* @func
* @memberOf R
* @category Function
* @sig (a -> b) -> (c -> d) -> (b -> c) -> (a -> d)
* @sig Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d
* @param {Function} f The preprocessor function, a -> b
* @param {Function} g The postprocessor function, c -> d
* @param {Profunctor} profunctor The profunctor instance to be promapped, e.g. b -> c
* @return {Profunctor} The new profunctor instance, e.g. a -> d
* @see R.transduce
* @example
*
* const decodeChar = R.promap(s => s.charCodeAt(), String.fromCharCode, R.add(-8))
* const decodeString = R.promap(R.split(''), R.join(''), R.map(decodeChar))
* decodeString("ziuli") //=> "ramda"
*
* @symb R.promap(f, g, h) = x => g(h(f(x)))
* @symb R.promap(f, g, profunctor) = profunctor.promap(f, g)
*/
var promap = _curry3(_dispatchable(['fantasy-land/promap', 'promap'], _xpromap, _promap));
export default promap;