Skip to content

Instantly share code, notes, and snippets.

@Raynos
Last active December 15, 2015 18: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 Raynos/484693963b9ef499f446 to your computer and use it in GitHub Desktop.
Save Raynos/484693963b9ef499f446 to your computer and use it in GitHub Desktop.
// map :: (A -> B) -> Continuable<A> -> Continuable<B>
function map(lambda) {
return function duplex(source) {
return function continuable(callback) {
source(function (err, value) {
callback(err, err ? null : lambda(value))
})
}
}
}
var source = function continuable(cb) {
cb(null, 42)
}
function sink(err, value) {
console.log("(", err, ", ", value, ")")
}
map(function (x) { return x * 2 })(source)(sink)
// map :: (A -> B) -> ContinuableStream<A> -> ContinuableStream<B>
function map(lambda) {
return function duplex(source) {
return return { read: return function read(cb) {
source.read()(function (err, value) {
cb(err, err ? null : lambda(value))
})
} }
}
}
// map :: (A -> B) -> PullStream<A> -> PullStream<B>
function map(lambda) {
return function duplex(source) {
return function stream(abort, callback) {
source(abort, function (err, value) {
callback(err, err ? null : lambda(value))
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment