forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromap.js
45 lines (36 loc) · 1.37 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
38
39
40
41
42
43
44
45
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
var Pair = require('./shared/Pair.js');
describe('promap', function() {
var fromCharCode = String.fromCharCode;
function charCodeAt(s) { return s.charCodeAt(); }
function Costar(run) {
return {
promap: function promap(f, g) {
return Costar(R.pipe(R.map(f), run, g));
},
run: run
};
}
it('dispatches to pronfuctor["fantasy-land/promap"]() if present', function() {
var setJson = R.promap(JSON.parse, JSON.stringify);
var pair = setJson(
Pair(R.assoc('left-promapped', true), R.assoc('right-promapped', true))
);
function mergeWithJson(json) {
return function(left, right) { return right(left(json)); };
}
eq(pair.merge(mergeWithJson('{}')), '{"left-promapped":true,"right-promapped":true}');
});
it('dispatches to pronfuctor.promap() if present', function() {
var is1337Change = R.promap(R.multiply(100), R.equals(1337), Costar(R.sum));
var data = [10, 3, 0.3, 0.07];
eq(is1337Change.run(data), true);
});
it('composes two functions, f and g, before and after the final function respectively', function() {
var decodeChar = R.promap(charCodeAt, fromCharCode, R.add(-8));
var decodeString = R.promap(R.split(''), R.join(''), R.map(decodeChar));
var code = 'ziuli';
eq(decodeString(code), 'ramda');
});
});