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