add stream folder with scan and scan-merge
This commit is contained in:
parent
db956d7194
commit
db445a899d
4 changed files with 147 additions and 0 deletions
26
stream/scan-merge.js
Normal file
26
stream/scan-merge.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
//! adapted for mithril from flyd https://github.com/paldepind/flyd
|
||||
'use strict'
|
||||
|
||||
var combine = require('../stream').combine
|
||||
|
||||
module.exports = function (tuples, seed) {
|
||||
var streams = tuples.map(function (tuple) {
|
||||
var stream = tuple[0]
|
||||
if (stream._state.state === 0) stream(undefined)
|
||||
return stream
|
||||
})
|
||||
|
||||
var newStream = combine(function () {
|
||||
var changed = arguments[arguments.length - 1]
|
||||
|
||||
streams.forEach(function (stream, idx) {
|
||||
if (changed.indexOf(stream) > -1) {
|
||||
seed = tuples[idx][1](seed, stream._state.value)
|
||||
}
|
||||
})
|
||||
|
||||
return seed
|
||||
}, streams)
|
||||
|
||||
return newStream
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue