update
This commit is contained in:
1 parent
be398bf5ce
commit
f121eff445
38 files changed
+498
-267
No files matched your search
@@ -79,3 +79,26 @@ export function assign(dict, key, value){
|
||||
export function map(v, fn) {
|
||||
return value => fn(value) ? v : value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* f(g, [x, y, z, ...]) => map of {g(x): x, g(y): y, g(z): z}
|
||||
*
|
||||
* @param list
|
||||
* @param selector
|
||||
* @returns {*}
|
||||
*/
|
||||
export function createMap(selector, list){
|
||||
return list.reduce((map, i) => map.set(selector(i), i), new Map());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* f(g) => x ? g(x) : null
|
||||
*
|
||||
* @param {function} fn
|
||||
* @returns {function(*=): null}
|
||||
*/
|
||||
export function nullSafe(fn){
|
||||
return i => i ? fn(i) : null;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
*
|
||||
* f([x, y, z, ...]) -> f(v) -> {v.x, v.y, v.z}
|
||||
*
|
||||
* @param fields
|
||||
* @returns {function(*): *}
|
||||
*/
|
||||
export function select(fields=[]){
|
||||
return i => fields.reduce((out, key) => {
|
||||
out[key] = i[key];
|
||||
return out;
|
||||
}, {});
|
||||
}
|
||||
Reference in new issue
Block a user