Fixed scan with skip (#2357)

* Fixed bad test for scan

The previous test didn't catch the fact that the accumulator had been
broke, it's value became the special value `SKIP`.

* Fixed Stream.scan() to accept SKIP value

* Update stream/stream.js

Dropped unnecessary ternary as suggested by @isiahmeadows

Co-Authored-By: gamb <adam@gamb.co>
This commit is contained in:
Adam Gamble 2019-01-10 04:10:02 +00:00 committed by Isiah Meadows
parent 65e2561c55
commit 23fe0a5ab1
2 changed files with 7 additions and 4 deletions

View file

@ -113,8 +113,9 @@ function merge(streams) {
function scan(fn, acc, origin) { function scan(fn, acc, origin) {
var stream = origin.map(function(v) { var stream = origin.map(function(v) {
acc = fn(acc, v) var next = fn(acc, v)
return acc if (next !== Stream.SKIP) acc = next
return next
}) })
stream(acc) stream(acc)
return stream return stream

View file

@ -51,15 +51,17 @@ o.spec("scan", function() {
action(7) action(7)
action("11") action("11")
action(undefined) action(undefined)
action({a: 1}) action({a: 1})
action(8) // assures we didn't break the accumulator
result = child() result = child()
// check we got the expect result // check we got the expect result
o(result[0]).equals(7) o(result[0]).equals(7)
o(result[1]).equals(8)
// check child received minimum # of updates // check child received minimum # of updates
o(count).equals(2) o(count).equals(3)
}) })
}) })