Skip to content

Instantly share code, notes, and snippets.

@davidchambers
Created April 19, 2015 17:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidchambers/9c757f3213a053cfe15d to your computer and use it in GitHub Desktop.
Save davidchambers/9c757f3213a053cfe15d to your computer and use it in GitHub Desktop.

Function composition has one huge benefit over chaining APIs: it allows any combination of JavaScript functions to be stuck together to form a pipeline. One could create a pipeline involving a function from library A, a function from library B, a function from library C, and a built-in function. With a chaining API one is restricted to the set of functions available on the object facilitating the chaining.

I found this to be a problem when using Underscore. This would be fine for a pipeline comprised solely of Underscore functions (represented here by lower-case identifiers):

_(x)
.a(...)
.b(...)
.c(...)
.value()

"Foreign" functions (represented here by upper-case identifiers) break the pipeline:

_(D(_(x)
    .a(...)
    .b(...)
    .c(...)
    .value()))
.e(...)
.f(...)
.value()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment