Skip to content

Instantly share code, notes, and snippets.

@fauxneticien
Created October 19, 2017 05:35
Show Gist options
  • Save fauxneticien/34531d1e255bb994de60aea34cb1a83a to your computer and use it in GitHub Desktop.
Save fauxneticien/34531d1e255bb994de60aea34cb1a83a to your computer and use it in GitHub Desktop.
Ecuder — the opposite of reduce
/*
// Helper to split an initial object into a nested array
// by Mark Ellison <https://github.com/tyrannomark> mostly!
ecuder([x => x.split(" ")])("one two")
ecuder([x => x.split(" "), x => x.split("")])("one two")
ecuder([x => x.split(/\.\s?/), x => x.split(" "), x => x.split("")])("sentence one. sentence two")
*/
function ecuder(funcs_array, initial_obj) {
return function ecuderR(initial_obj) {
if(!funcs_array.length) return initial_obj
return funcs_array[0](initial_obj).map(ecuder(funcs_array.slice(1)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment