Created
June 10, 2020 16:29
-
-
Save dinocarl/636245160ae8df89db0e359f6e3a1266 to your computer and use it in GitHub Desktop.
Apply an object of functions to 2 others of Data to arrive at a new one where each key has had its special function run against the other's values.
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 selectBrevity= (l, r) => lte(length(l), length(r)) | |
? l | |
: r; | |
const lispy = ([fn, ...args]) => fn(...args); | |
const makeSet = (arr) => uniq(flatten(arr)); | |
const zipObjLisped = (arr) => ({ [head(arr)]: lispy(tail(arr)) }); | |
const medianArgs = (...args) => median([...args]) | |
const sumArgs = (...args) => sum([...args]) | |
const mergeWithStrategy = (rubrick, a, b) => compose( | |
reduce( | |
(acc, item) => merge(acc, zipObjLisped(makeSet(item))), | |
{} | |
), | |
zip(toPairs(rubrick)), | |
zip(toPairs(a)) | |
)(toPairs(b)); | |
const dataA = { | |
baths: 2, | |
beds: 1, | |
type: 'residential', | |
year: 2011, | |
}; | |
const dataB = { | |
baths: 4, | |
beds: 5, | |
type: 'single family residential', | |
year: 2008, | |
}; | |
const elegantePrimo = { | |
baths: medianArgs, | |
beds: max, | |
type: selectBrevity, | |
year: sumArgs, | |
}; | |
mergeWithStrategy( | |
elegantePrimo, | |
dataA, | |
dataB | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment