mirror of
https://github.com/composewell/streamly.git
synced 2024-11-10 12:47:22 +03:00
simplify last
This commit is contained in:
parent
162cb8b2fb
commit
689b9c53b8
@ -306,19 +306,7 @@ runStream (Stream step state) = go SPEC state
|
||||
|
||||
{-# INLINE_NORMAL last #-}
|
||||
last :: Monad m => Stream m a -> m (Maybe a)
|
||||
last (Stream step state) = go0 SPEC state
|
||||
where
|
||||
go0 !_ st = do
|
||||
r <- step st
|
||||
case r of
|
||||
Yield x s -> go1 SPEC x s
|
||||
Stop -> return Nothing
|
||||
|
||||
go1 !_ x st = do
|
||||
r <- step st
|
||||
case r of
|
||||
Yield y s -> go1 SPEC y s
|
||||
Stop -> return (Just x)
|
||||
last = foldl' (\_ y -> Just y) Nothing
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Map and Fold
|
||||
|
Loading…
Reference in New Issue
Block a user