Last active
August 26, 2016 00:09
-
-
Save emyann/668ea9746c420304b0fe08e7913d77cc to your computer and use it in GitHub Desktop.
This curried function return a function that allows to transform any collection of object towards another collection by using a translation schema
This file contains 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
// This curried function return a function that allows to transform any collection of object towards another collection by using a translation schema | |
// use it like like | |
// let extractSomething = fieldMapper({ wantedProp:'TargetProperty', wantedProp1: 'target.property'}); | |
// let transformedCollection = extractSomething(dataToTransform) | |
fieldMapper(schema) { | |
let _schema = _.clone(schema); | |
return (items) => { | |
return _.chain(items) | |
.map((obj) => { | |
return _.mapValues(_schema, (path) => { | |
return _.get(obj, path); | |
}); | |
}).value(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment