s/sync/merge
This commit is contained in:
parent
5f90bde20f
commit
a2680b30a4
3 changed files with 22 additions and 10 deletions
14
docs/prop.md
14
docs/prop.md
|
|
@ -4,6 +4,7 @@
|
||||||
- [Static members](#static-members)
|
- [Static members](#static-members)
|
||||||
- [prop.combine](#prop-combine)
|
- [prop.combine](#prop-combine)
|
||||||
- [prop.reject](#prop-reject)
|
- [prop.reject](#prop-reject)
|
||||||
|
- [prop.merge](#prop-merge)
|
||||||
- [prop.HALT](#prop-halt)
|
- [prop.HALT](#prop-halt)
|
||||||
- [Instance members](#static-members)
|
- [Instance members](#static-members)
|
||||||
- [stream.run](#stream-run)
|
- [stream.run](#stream-run)
|
||||||
|
|
@ -85,6 +86,19 @@ Argument | Type | Required | Description
|
||||||
|
|
||||||
[How to read signatures](signatures.md)
|
[How to read signatures](signatures.md)
|
||||||
|
|
||||||
|
##### prop.merge
|
||||||
|
|
||||||
|
Creates a stream whose value is the array of values from an array of streams
|
||||||
|
|
||||||
|
`stream = m.prop.merge(streams)`
|
||||||
|
|
||||||
|
Argument | Type | Required | Description
|
||||||
|
------------ | -------------------- | -------- | ---
|
||||||
|
`streams` | `Array<Stream>` | Yes | A list of streams
|
||||||
|
**returns** | `Stream` | | Returns a stream whose value is an array of input stream values
|
||||||
|
|
||||||
|
[How to read signatures](signatures.md)
|
||||||
|
|
||||||
##### prop.HALT
|
##### prop.HALT
|
||||||
|
|
||||||
A special value that can be returned to stream callbacks to halt execution of downstreams
|
A special value that can be returned to stream callbacks to halt execution of downstreams
|
||||||
|
|
|
||||||
|
|
@ -174,12 +174,10 @@ function reject(e) {
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
function sync (streams) {
|
function merge(streams) {
|
||||||
return combine(function () {
|
return combine(function () {
|
||||||
return Array.prototype.slice
|
return streams.map(function (s) {return s()})
|
||||||
.call(arguments, 0, arguments.length-1)
|
|
||||||
.map(function (s) { return s() })
|
|
||||||
}, streams)
|
}, streams)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {stream: createStream, sync: sync, combine: combine, reject: reject, HALT: HALT}
|
module.exports = {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
||||||
|
|
|
||||||
|
|
@ -166,20 +166,20 @@ o.spec("stream", function() {
|
||||||
o(b()).equals(undefined)
|
o(b()).equals(undefined)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o.spec("sync", function() {
|
o.spec("merge", function() {
|
||||||
o("transforms an array of streams to an array of values", function() {
|
o("transforms an array of streams to an array of values", function() {
|
||||||
var all = Stream.sync([
|
var all = Stream.merge([
|
||||||
Stream.stream(10),
|
Stream.stream(10),
|
||||||
Stream.stream("20"),
|
Stream.stream("20"),
|
||||||
Stream.stream({ value: 30 }),
|
Stream.stream({value: 30}),
|
||||||
])
|
])
|
||||||
|
|
||||||
o(all()).deepEquals([10, "20", { value: 30 }])
|
o(all()).deepEquals([10, "20", {value: 30}])
|
||||||
})
|
})
|
||||||
o("remains pending until all streams are active", function() {
|
o("remains pending until all streams are active", function() {
|
||||||
var straggler = Stream.stream()
|
var straggler = Stream.stream()
|
||||||
|
|
||||||
var all = Stream.sync([
|
var all = Stream.merge([
|
||||||
Stream.stream(10),
|
Stream.stream(10),
|
||||||
Stream.stream("20"),
|
Stream.stream("20"),
|
||||||
straggler,
|
straggler,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue