Skip to content

Instantly share code, notes, and snippets.

@tincho
Created February 6, 2020 20:03
Show Gist options
  • Save tincho/a44c336a033105f21b7a1aa7b1a791dd to your computer and use it in GitHub Desktop.
Save tincho/a44c336a033105f21b7a1aa7b1a791dd to your computer and use it in GitHub Desktop.
// @params: N functions that should return an Object
// @returns a fn that will pass all arg to all fns and return an Obj with all outputs merged
const mergeOutputs = (...fns) => (...args) => fns.reduce((out, fn) => ({
...out,
...fn(...args)
}), {})
// takes one arg
const one = (name) => ({ hello: name, world: name })
// takes two arg
const two = (name, lastname) => ({ fullName: `${name} ${lastname}` })
const objectMaker = mergeOutputs(one,two)
console.log(objectMaker('martin', 'salinas'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment