forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho.js
47 lines (38 loc) · 1.23 KB
/
o.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
46
47
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
var fc = require('fast-check');
describe('o', function() {
it('is not a variadic function', function() {
eq(typeof R.o, 'function');
eq(R.o.length, 3);
});
it('is a curried function', function() {
eq(R.o(R.add(1), R.multiply(2), 10), R.o(R.add(1))(R.multiply(2))(10));
});
it('performs right-to-left function composition', function() {
// f :: Number -> ([Number] -> [Number])
var f = R.o(R.map, R.multiply);
eq(f.length, 1);
eq(f(10)([1, 2, 3]), [10, 20, 30]);
});
describe('o properties', function() {
it('composes two functions', function() {
fc.assert(fc.property(fc.func(fc.nat()), fc.func(fc.nat()), fc.nat(), function(f, g, x) {
return R.equals(R.o(f, g)(x), f(g(x)));
}));
});
it('associative', function() {
fc.assert(fc.property(fc.func(fc.nat()), fc.func(fc.nat()), fc.func(fc.nat()), fc.nat(), function(f, g, h, x) {
var result = f(g(h(x)));
var fg = R.o(f, g);
var gh = R.o(g, h);
return R.all(R.equals(result), [
R.o(f, gh, x),
R.o(fg, h, x),
R.o(f, gh)(x),
R.o(fg, h)(x)
]);
}));
});
});
});