Scan with halt (#1957)

* HALT if scan reducer doesn't change value

* Updated docs to reflect new scan behaviour with HALT
This commit is contained in:
Adam Gamble 2018-05-03 16:52:33 +01:00 committed by Barney Carroll
parent 117fac91a7
commit fb3c344055
3 changed files with 38 additions and 2 deletions

View file

@ -117,7 +117,9 @@ function merge(streams) {
function scan(reducer, seed, stream) {
var newStream = combine(function (s) {
return seed = reducer(seed, s._state.value)
var next = reducer(seed, s._state.value)
if (next !== HALT) return seed = next
return HALT
}, [stream])
if (newStream._state.state === 0) newStream(seed)