Skip to content

Instantly share code, notes, and snippets.

@creationix
Last active January 4, 2016 06:49
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 creationix/f43c29e3e6da09e4f8b6 to your computer and use it in GitHub Desktop.
Save creationix/f43c29e3e6da09e4f8b6 to your computer and use it in GitHub Desktop.
function transform(emit) {
// any state kept between input chunks will be setup here
return function (item) {
// Forward the EOS marker
if (item === undefined) return emit();
// Skip cheese items
if (item === "cheese") return;
// Double anything else
emit(item);
emit(item);
// This example is silly, but it shows that you can call emit 0 or more times for every item input.
};
}
someObject.on("data", transform(function (out) {
// every data event will run through the filter and emit here.
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment