@@ -4136,19 +4136,21 @@ tapAsync f (Stream step1 state1) = Stream step TapInit
41364136-- | Take last 'n' elements from the stream and discard the rest.
41374137{-# INLINE lastN #-}
41384138lastN :: (Storable a, MonadIO m) => Int -> Fold m a (Array a)
4139−lastN n = Fold step initial done
4140− where
4141− step (Tuple3' rb rh i) a = do
4142− rh1 <- liftIO $ RB.unsafeInsert rb rh a
4143− return $ Tuple3' rb rh1 (i + 1)
4144− initial = fmap (\(a, b) -> Tuple3' a b (0 :: Int)) $ liftIO $ RB.new n
4145− done (Tuple3' rb rh i) = do
4146− arr <- liftIO $ A.newArray n
4147− foldFunc i rh snoc' arr rb
4148− snoc' b a = liftIO $ A.unsafeSnoc b a
4149− foldFunc i
4150− | i < n = RB.unsafeFoldRingM
4151− | otherwise = RB.unsafeFoldRingFullM
4139+lastN n
4140+ | n <= 0 = fmap (const mempty) FL.drain
4141+ | otherwise = Fold step initial done
4142+ where
4143+ step (Tuple3' rb rh i) a = do
4144+ rh1 <- liftIO $ RB.unsafeInsert rb rh a
4145+ return $ Tuple3' rb rh1 (i + 1)
4146+ initial = fmap (\(a, b) -> Tuple3' a b (0 :: Int)) $ liftIO $ RB.new n
4147+ done (Tuple3' rb rh i) = do
4148+ arr <- liftIO $ A.newArray n
4149+ foldFunc i rh snoc' arr rb
4150+ snoc' b a = liftIO $ A.unsafeSnoc b a
4151+ foldFunc i
4152+ | i < n = RB.unsafeFoldRingM
4153+ | otherwise = RB.unsafeFoldRingFullM
41524154
41534155------------------------------------------------------------------------------
41544156-- Time related