This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wait = delay => { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve('Hello'); | |
}, delay); | |
}); | |
}; | |
wait(5000).then(r => console.log(r)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Data example | |
const items = [{name: 'Bruce' }, {name: 'Fabs'}, {name: 'Bruce'}, {name: 'Gaby'}]; | |
/** | |
* @description Filter by one where condition | |
* @param w Where condition function | |
* @returns {Function} filter function | |
*/ | |
const filter = w => a => a.filter(w); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description Compose function to compose functions | |
* @param fns Functions to reduce on composition | |
* @returns {Function} Compose function | |
*/ | |
const compose = (...fns) => x => fns.reduceRight((f, m) => m(f), x); | |
// Combine functions | |
compose( | |
map(applier('age', 33)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Data example | |
const items = [{name: 'Bruce' }, {name: 'Fabs'}, {name: 'Bruce'}, {name: 'Gaby'}]; | |
/** | |
* @description Filter by one where condition | |
* @param w Where condition function | |
* @returns {Function} filter function | |
*/ | |
const filter = w => a => a.filter(w); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = [{name: 'Bruce' }, {name: 'Fabs'}, {name: 'Bruce'}, {name: 'Gaby'}]; | |
const filter = w => a => a.filter(w); | |
const where = (k, v) => i => i[k] === v; | |
const map = fnMap => f => f.map(fnMap); | |
const applier = (k, v) => x => x[k] = v; | |
map(applier('lastname', 'Wayne'))(filter(where('name', 'Bruce'))(items)) | |
console.log(items); | |
/* | |
[{ name: 'Bruce', lastname: 'Wayne' }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = [{name: 'Bruce' }, {name: 'Fabs'}, {name: 'Bruce'}, {name: 'Gaby'}]; | |
const filter = function(key, value){ | |
return function(i){ | |
return i[key] === value; | |
} | |
} | |
const applier = function(key, value){ | |
return function(i){ | |
i[key] = value; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = [{name: 'Bruce' }, {name: 'Fabs'}, {name: 'Bruce'}, {name: 'Gaby'}]; | |
items.filter(function(i){ | |
return i.name === 'Bruce'; | |
}).map(function(i){ | |
i.lastname = 'Wayne'; | |
}); | |
console.log(items); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const list = [1, 2, 3]; | |
const map = arr => fn => arr.map(fn); | |
const double = i => i * 2; | |
map(list)(double); //[2, 4, 6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const list = [1, 2, 3]; | |
function double(i) { | |
return i * 2; | |
} | |
function map (arr, fn) { | |
return arr.map(fn); | |
} | |
map(list, double); //[2, 4, 6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const list = [1, 2, 3]; | |
function map(arr) { | |
return arr.map(function double(i){ | |
return i * 2; | |
}) | |
} | |
map(list); // [2, 4, 6] |