@@ -87,7 +87,6 @@ import qualified System.IO as IO
8787
8888import Streamly.Core
8989import Streamly.Streams
90−
9190------------------------------------------------------------------------------
9291-- Construction
9392------------------------------------------------------------------------------
@@ -334,14 +333,9 @@ head m =
334333 in (runStream (toStream m)) Nothing stop yield
335334
336335-- | Extract the last element of the stream, if any.
336+{-# INLINE last #-}
337337last :: (Streaming t, Monad m) => t m a -> m (Maybe a)
338−last m = go (toStream m)
339− where
340− go m1 =
341− let stop = return Nothing
342− yield a Nothing = return (Just a)
343− yield _ (Just x) = go x
344− in (runStream m1) Nothing stop yield
338+last = foldl (\_ y -> Just y) Nothing id
345339
346340-- | Determine whether an element is present in the stream.
347341elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool