Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Fixed `Stream.postscanl` to omit the output of a scan that terminates without
consuming any input (e.g. `Scanl.take 0`).
* Breaking: In `FileSystem.Path` module the default for `eqPath` changed
on Windows to case-sensitive comparison.
* Breaking: A leading "." component (e.g. "." or "./x") is no longer
Expand Down
20 changes: 16 additions & 4 deletions core/src/Streamly/Internal/Data/Stream/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,24 @@ data ScanState s f = ScanInit s | ScanDo s !f | ScanDone
-- Unfortunately, we cannot define lazy scans because the Partial constructor
-- itself is strict.

-- | Postscan a stream using the given fold. A postscan omits the initial
-- (default) value of the accumulator and includes the final value.
-- | Postscan a stream using the given scan. A postscan emits one output per
-- input element, omitting the initial value of the accumulator. Equivalently,
-- @postscanl s = 'Data.List.drop' 1 . 'scanl' s@.
--
-- >>> Stream.toList $ Stream.postscanl Scanl.latest (Stream.fromList [])
-- []
--
-- Compare with 'scan' which includes the initial value as well:
-- Compare with 'scanl' which additionally emits the initial value:
--
-- >>> Stream.toList $ Stream.scanl Scanl.latest (Stream.fromList [])
-- [Nothing]
--
-- A scan that terminates at the initial step (e.g. @Scanl.take 0@) consumes no
-- input, so the postscan is empty:
--
-- >>> Stream.toList $ Stream.postscanl (Scanl.take 0 Scanl.toList) (Stream.fromList [1,2,3::Int])
-- []
--
-- The following example extracts the input stream up to a point where the
-- running average of elements is no more than 10:
--
Expand Down Expand Up @@ -575,7 +582,12 @@ postscanl (Scanl fstep initial extract final) (Stream sstep state) =
return
$ case res of
FL.Partial fs -> Skip $ ScanDo st fs
FL.Done b -> Yield b ScanDone
-- A scan that is Done at the initial step has consumed no
-- input, so a postscan (one output per consumed input) emits
-- nothing. This keeps the invariant
-- @postscanl s = drop 1 . scanl s@: the initial value is
-- always dropped, whether it comes from a Partial or a Done.
FL.Done _ -> Stop
step gst (ScanDo st fs) = do
res <- sstep (adaptState gst) st
case res of
Expand Down
6 changes: 3 additions & 3 deletions streamly.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ extra-source-files:
test/Streamly/Test/Data/*.hs
test/Streamly/Test/Data/Array/*.hs
test/Streamly/Test/Data/MutArray/*.hs
test/Streamly/Test/Data/Parser/*.hs
test/Streamly/Test/Data/ParserK/*.hs
test/Streamly/Test/Data/RingArray/*.hs
test/Streamly/Test/Data/Stream/*.hs
test/Streamly/Test/Data/Stream/MkType/*.hs
test/Streamly/Test/Data/Stream/Prelude/*.hs
Expand All @@ -145,7 +147,6 @@ extra-source-files:
test/Streamly/Test/Prelude.hs
test/Streamly/Test/Prelude/*.hs
test/Streamly/Test/Unicode/*.hs
test/Streamly/Test/Serialize/*.hs
test/Streamly/Test/Data/Scanl/*.hs
test/Streamly/Test/Data/Fold/*.hs
test/Streamly/Test/Unicode/ucd/NormalizationTest.txt
Expand All @@ -154,8 +155,7 @@ extra-source-files:
test/lib/Streamly/Test/Common.hs
test/lib/Streamly/Test/Control/Exception/Common.hs
test/lib/Streamly/Test/Prelude/Common.hs
test/lib/Streamly/Test/Data/Parser/CommonTests.hs
test/lib/Streamly/Test/Data/Parser/CommonUtilities.hs
test/lib/Streamly/Test/Data/Parser/*.hs
test/streamly-tests.cabal
test/version-bounds.hs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ charLatin1 = forAll (chooseChar (unsafeChr 0, unsafeChr 255)) $ \x ->
monadicIO $ action x Encoder.charLatin1 Decoder.charLatin1

moduleName :: String
moduleName = "Serialize.Serializable"
moduleName = "Data.Binary"

main :: IO ()
main =
Expand Down
3 changes: 0 additions & 3 deletions test/Streamly/Test/Data/Fold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import qualified Streamly.Test.Data.Fold.Container as Container
import qualified Streamly.Test.Data.Fold.Exception as Exception
import qualified Streamly.Test.Data.Fold.Tee as Tee
import qualified Streamly.Test.Data.Fold.Type as Type
import qualified Streamly.Test.Data.Fold.Window as Window

main :: IO ()
main = do
Type.main
Combinators.main
Container.main
Window.main
Exception.main
Tee.main
Loading
Loading