From 23fe0a5ab1b60626b88da1a206789dfdc81b506c Mon Sep 17 00:00:00 2001 From: Adam Gamble Date: Thu, 10 Jan 2019 04:10:02 +0000 Subject: [PATCH] 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 --- stream/stream.js | 5 +++-- stream/tests/test-scan.js | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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) }) })