-
-
Save Raynos/484693963b9ef499f446 to your computer and use it in GitHub Desktop.
This file contains 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
// 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) |
This file contains 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
// 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)) | |
}) | |
} } | |
} | |
} |
This file contains 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
// 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