+ common utils: unique, assign, map
This commit is contained in:
1 parent
6b7a77fb15
commit
b21144e87d
1 file changed
+28
-1
+28
-1
@@ -51,4 +51,31 @@ export function select(byCondition, map = i => i) {
|
|||||||
*/
|
*/
|
||||||
export function choise(scope, selector){
|
export function choise(scope, selector){
|
||||||
return scope.reduce(selector, null);
|
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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user