diff --git a/stream/stream.js b/stream/stream.js index 4a703ce9..08f27628 100644 --- a/stream/stream.js +++ b/stream/stream.js @@ -113,8 +113,9 @@ function merge(streams) { function scan(fn, acc, origin) { var stream = origin.map(function(v) { - acc = fn(acc, v) - return acc + var next = fn(acc, v) + if (next !== Stream.SKIP) acc = next + return next }) stream(acc) return stream diff --git a/stream/tests/test-scan.js b/stream/tests/test-scan.js index 04423729..6dc30e58 100644 --- a/stream/tests/test-scan.js +++ b/stream/tests/test-scan.js @@ -51,15 +51,17 @@ o.spec("scan", function() { action(7) action("11") action(undefined) - action({a: 1}) + action({a: 1}) + action(8) // assures we didn't break the accumulator result = child() // check we got the expect result o(result[0]).equals(7) + o(result[1]).equals(8) // check child received minimum # of updates - o(count).equals(2) + o(count).equals(3) }) })