Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anirudh-eka/9c8efe1e73251625b16b2e9714acf721 to your computer and use it in GitHub Desktop.
Save anirudh-eka/9c8efe1e73251625b16b2e9714acf721 to your computer and use it in GitHub Desktop.
const mapping = mapLogic => reducer => (a, x) => {
const transformed = mapLogic(x);
return reducer(a, transformed)
}
const filtering = filterLogic => reducer => (a, x) => {
if(filterLogic(x)) {
return reducer(a, x)
} else {
return a;
}
}
const trance = compose([filtering(x => x > 2), mapping(x => x + 1)]);
[1, 2, 3].reduce(trance((a, x) => a.concat(x)), []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment