Skip to content

Commit 2be3c4f

Browse files
authored
feature(PRELUDE) simplify
1 parent 7e89042 commit 2be3c4f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

prelude.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
'use strict'
22

3-
const compose = (f, g) => x => f(g(x))
3+
const _compose = function _compose(f, g) {
4+
return function () {
5+
return f(g.apply(null, arguments));
6+
};
7+
};
8+
9+
const compose = fns => fns.reduce(_compose)
410

511
const uniq = xs => xs.reduce((list, x) => list.indexOf(x) === -1 ? list.concat(x) : list, [])
612

713
const identity = x => x
814

9-
const flatten = xs => [].concat.apply([], xs.map(identity));
15+
const concat = (xs, list) => xs.concat(list)
16+
17+
const union = compose([uniq, identity])
18+
19+
const join = separator => xs => xs.join(separator)
20+
21+
const split = separator => str => str.split(separator)
22+
23+
const pathUnion = compose([join('/'), union, split('/'), concat])
1024

11-
exports.union = compose(uniq, flatten)
25+
exports.pathUnion = pathUnion

0 commit comments

Comments
 (0)