+ common utils: unique, assign, map

This commit is contained in:
tmshv committed 2016-03-03 01:29:17 +03:00
1 parent 6b7a77fb15
commit b21144e87d
1 file changed
+28 -1
+28 -1
View File
@@ -51,4 +51,31 @@ export function select(byCondition, map = i => i) {
*/
export function choise(scope, selector){
return scope.reduce(selector, null);
}
}
export function unique(fn) {
return list => [...new Set(list.map(fn))];
}
export function branch(fn) {
let keys = unique(fn);
return list => keys(list)
.reduce((dict, key) => {
dict[key] = list.filter(
i => fn(i) === key
);
return dict;
}, {})
}
export function assign(dict, key, value){
dict[key] = value;
return dict;
}
export function map(v, fn) {
return value => fn(value) ? v : value;
}