mirror of
https://github.com/composewell/streamly.git
synced 2024-09-21 08:31:42 +03:00
Merge pull request #25 from Abhiroop/last
Fix last for streams that end with "stop" continuation
This commit is contained in:
commit
f5a21bcae9
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user