Created
May 2, 2013 15:04
-
-
Save creationix/5502841 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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