Skip to content

Commit

Permalink
Fixed scan with skip (#2357)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Adam Gamble authored and dead-claudia committed Jan 10, 2019
1 parent 65e2561 commit 23fe0a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions stream/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions stream/tests/test-scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

})

0 comments on commit 23fe0a5

Please sign in to comment.