Add Stream.lift (#1950)

* Add stream.lift and tests

* Add docs

* Add to change-log
This commit is contained in:
spacejack 2018-11-13 18:55:45 -05:00 committed by Isiah Meadows
parent a147023f4e
commit 76e585c523
4 changed files with 180 additions and 1 deletions

View file

@ -63,7 +63,7 @@ function finalize(stream) {
}
function combine(fn, streams) {
if (!streams.every(valid)) throw new Error("Ensure that each item passed to stream.combine/stream.merge is a stream")
if (!streams.every(valid)) throw new Error("Ensure that each item passed to stream.combine/merge/lift is a stream")
return initDependency(createStream(), streams, function() {
return fn.apply(this, streams.concat([streams.filter(changed)]))
})
@ -148,11 +148,20 @@ function scanMerge(tuples, seed) {
return newStream
}
function lift() {
var fn = arguments[0]
var streams = Array.prototype.slice.call(arguments, 1)
return merge(streams).map(function(streams) {
return fn.apply(undefined, streams)
})
}
createStream["fantasy-land/of"] = createStream
createStream.merge = merge
createStream.combine = combine
createStream.scan = scan
createStream.scanMerge = scanMerge
createStream.lift = lift
createStream.HALT = HALT
if (typeof module !== "undefined") module["exports"] = createStream