Skip to content

Instantly share code, notes, and snippets.

@karlpokus
Last active September 27, 2016 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlpokus/6d2e930e44b1b6b3682b8ff301eabd26 to your computer and use it in GitHub Desktop.
Save karlpokus/6d2e930e44b1b6b3682b8ff301eabd26 to your computer and use it in GitHub Desktop.
Piping is fun! Maybe control flow is a more suitable title but who cares?

Piping is fun!

unix

$ ls | grep test

ExpressJS

app.get('/', fn1, fn2, fn3); // or pass an array
app.use(errorHandler);

node streams

readable.pipe(transform).pipe(writable);

jQuery chaining

$('a').parent().next().filter('b').text();

Promises

getData(data)
  .then(compute)
  .then(computeSomeMore);

pype

Do we need a shared context?

Do we need a nice name? Should we curry? Composing like baos?

How to pass data?

  • data object?
  • via next?
  • this?

Handling errors?

  • centralized?
  • bound?

Server

// pass data via req
// pass error to centralized errorHandler
pype(context, stack, errorHandler, finalHandler)(req, res);

Client

// pass data via data object
// pass error to centralized errorHandler
// #1
pype(context, stack, errorHandler, finalHandler)(data);
// #2
pype(data, errorHandler stack);
// #3
pype(data, fn1, fn2, fn3); // bound errorHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment