Skip to content

Commit 8561d61

Browse files
Correct the Scan module example and the demuxKvToMap definition
In the Streamly.Data.Scan example, "Scan.compose scan1 scan3" runs scan3 first, so it computed (x^2 + 3x)^2 instead of the stated x^4 + 3x^2. Swap the arguments and run main in the example to show the output. The demuxKvToMap definition applied "Fold.lmap snd" to the monadic Maybe result of the key function instead of to the fold inside it.
1 parent 7198634 commit 8561d61

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎core/src/Streamly/Data/Scan.hs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
-- >>> scan1 = Scan.function (\x -> x * x)
2929
-- >>> scan2 = Scan.function (\x -> 3 * x)
3030
-- >>> scan3 = Scan.teeWith (+) scan1 scan2 -- Compute x^2 + 3x
31-
-- >>> scan4 = Scan.compose scan1 scan3 -- compute x^2 then pass it to scan3
31+
-- >>> scan4 = Scan.compose scan3 scan1 -- compute x^2 then pass it to scan3
3232
--
3333
-- >>> :{
3434
-- main =
@@ -38,6 +38,11 @@
3838
-- & Stream.fold (Fold.drainMapM print) -- IO ()
3939
-- :}
4040
--
41+
-- >>> main
42+
-- 8
43+
-- 32
44+
-- 112
45+
--
4146
-- @scan3@ splits the computation into two parts, one part computes @x^2@ using
4247
-- @scan1@ and the other part computes @3x@ using @scan2@ and then it zips the
4348
-- two parts back into a single stream by summing them. @scan4@ first passes an

‎core/src/Streamly/Internal/Data/Fold/Container.hs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ demuxKvToContainer f = demuxerToContainer fst (fmap (fmap (lmap snd)) . f)
880880
--
881881
-- Definition:
882882
--
883-
-- >>> demuxKvToMap f = Fold.demuxerToContainer fst (Fold.lmap snd . f)
883+
-- >>> demuxKvToMap f = Fold.demuxerToContainer fst (fmap (fmap (Fold.lmap snd)) . f)
884884
--
885885
-- Example:
886886
--

0 commit comments

Comments
 (0)