Skip to content
Open
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
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Added `nubOrd` and friends.

Generalized the type of `chunksOf` and made it handle effects better.
(Thanks, Torgeir Strand Henriksen.)

- 0.2.1.0

Adding `Semigroup` instances for GHC 8.4.
Expand Down
14 changes: 8 additions & 6 deletions src/Streaming/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,14 @@ takes n = void . splitsAt n
2
1
-}
chunksOf :: (Monad m, Functor f) => Int -> Stream f m r -> Stream (Stream f m) m r
chunksOf n0 = loop where
loop stream = case stream of
Return r -> Return r
Effect m -> Effect (fmap loop m)
Step fs -> Step (Step (fmap (fmap loop . splitsAt (n0-1)) fs))
chunksOf :: (Functor f, Monad m, Monad n) => Int -> Stream f m r -> Stream (Stream f m) n r
chunksOf = go
where
go !n s = do
stage <- yields $ lift . inspect =<< splitsAt n s
case stage of
Left r -> pure r
Right s' -> go n $ wrap s'
{-# INLINABLE chunksOf #-}

{- | Make it possible to \'run\' the underlying transformed monad.
Expand Down