@@ -185,6 +185,9 @@ module Streamly.Internal.Data.Fold.Types
185 , Fold2 (..)
185 , Fold2 (..)
186 , simplify
186 , simplify
188 -- * Generators
191 -- * Generators
@@ -410,6 +413,23 @@ simplify :: Functor m => Fold2 m c a b -> c -> Fold m a b
410simplify (Fold2 step inject extract) c =
413simplify (Fold2 step inject extract) c =
411 Fold (\x a -> Partial <$> step x a) (Partial <$> inject c) extract
414 Fold (\x a -> Partial <$> step x a) (Partial <$> inject c) extract
416+------------------------------------------------------------------------------
418+------------------------------------------------------------------------------
420+-- | Folds the input stream to a list.
422+-- /Warning!/ working on large lists accumulated as buffers in memory could be
423+-- very inefficient, consider using "Streamly.Data.Array.Storable.Foreign"
428+-- id . (x1 :) . (x2 :) . (x3 :) . ... . (xn :) $ []
429+{-# INLINABLE toList #-}
430+toList :: Monad m => Fold m a [a]
431+toList = mkAccum (\f x -> f . (x :)) id ($ [])
413------------------------------------------------------------------------------
433------------------------------------------------------------------------------
414-- Instances
434-- Instances
415------------------------------------------------------------------------------
435------------------------------------------------------------------------------