Add m.prop.sync

This commit is contained in:
Gilbert 2016-07-12 22:57:09 -05:00
parent 7227cc546f
commit 008ffc9587
4 changed files with 90 additions and 1 deletions

View file

@ -174,4 +174,12 @@ function reject(e) {
return stream
}
module.exports = {stream: createStream, combine: combine, reject: reject, HALT: HALT}
function sync (streams) {
return combine(function () {
return Array.prototype.slice
.call(arguments, 0, arguments.length-1)
.map(function (s) { return s() })
}, streams)
}
module.exports = {stream: createStream, sync: sync, combine: combine, reject: reject, HALT: HALT}

View file

@ -166,6 +166,31 @@ o.spec("stream", function() {
o(b()).equals(undefined)
})
})
o.spec("sync", function() {
o("transforms an array of streams to an array of values", function() {
var all = Stream.sync([
Stream.stream(10),
Stream.stream("20"),
Stream.stream({ value: 30 }),
])
o(all()).deepEquals([10, "20", { value: 30 }])
})
o("remains pending until all streams are active", function() {
var straggler = Stream.stream()
var all = Stream.sync([
Stream.stream(10),
Stream.stream("20"),
straggler,
])
o(all()).equals(undefined)
straggler(30)
o(all()).deepEquals([10, "20", 30])
})
})
o.spec("end", function() {
o("end stream works", function() {
var stream = Stream.stream()