Created
December 10, 2018 22:11
-
-
Save bpinedah/3be0f4411919e700f235943e751f07de to your computer and use it in GitHub Desktop.
Currying article
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); | |
/** | |
* @description Create a where condition function | |
* @param k Criteria key name | |
* @param v Criteria value | |
* @returns {Function} Where condition function | |
*/ | |
const where = (k, v) => i => i[k] === v; | |
/** | |
* @description Create a map function | |
* @param fnMap Function to set on map callback | |
* @returns {Function} Map function | |
*/ | |
const map = fnMap => f => f.map(fnMap); | |
/** | |
* @description Create a modification function | |
* @param k Key to set any value | |
* @param v Value to set | |
* @returns {Function} Modification function | |
*/ | |
const applier = (k, v) => x => x[k] = v; | |
// Apply the modification | |
map(applier('lastname', 'Wayne'))(filter(where('name', 'Bruce'))(items)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment