Merge pull request #25 from Abhiroop/last

Fix last for streams that end with "stop" continuation
This commit is contained in:
Harendra Kumar 2018-03-15 13:48:17 +05:30 committed by GitHub
commit f5a21bcae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View File

@ -5,7 +5,8 @@
* Improve performance of some stream operations (`foldl`, `dropWhile`)
### Bug Fixes
* Fix the `product` operation. Earlier, it always returned 0 due to a bug.
* Fix the `product` operation. Earlier, it always returned 0 due to a bug
* Fix the `last` operation, which returned `Nothing` for singleton streams
## 0.1.0

View File

@ -87,7 +87,6 @@ import qualified System.IO as IO
import Streamly.Core
import Streamly.Streams
------------------------------------------------------------------------------
-- Construction
------------------------------------------------------------------------------
@ -334,14 +333,9 @@ head m =
in (runStream (toStream m)) Nothing stop yield
-- | Extract the last element of the stream, if any.
{-# INLINE last #-}
last :: (Streaming t, Monad m) => t m a -> m (Maybe a)
last m = go (toStream m)
where
go m1 =
let stop = return Nothing
yield a Nothing = return (Just a)
yield _ (Just x) = go x
in (runStream m1) Nothing stop yield
last = foldl (\_ y -> Just y) Nothing id
-- | Determine whether an element is present in the stream.
elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool