Skip to content

Instantly share code, notes, and snippets.

@creationix
Created May 2, 2013 15:04
Show Gist options
  • Save creationix/5502841 to your computer and use it in GitHub Desktop.
Save creationix/5502841 to your computer and use it in GitHub Desktop.
// Accepts a map function, return a push-filter function.
function mapToPush(map) {
return function (emit) {
return function (err, item) {
if (item === undefined) return emit(err);
emit(null, map(item));
};
};
}
// Accepts a map function, returns a pull-filter function
function mapToPull(map) {
return function (read) {
return function (close, callback) {
if (close) return read(close);
read(null, function (err, item) {
if (item === undefined) return callback(err);
callback(null, map(item));
});
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment