feat: Pipes.Collect
This commit is contained in:
parent
30fbce3a2d
commit
f373334f77
@ -32,7 +32,6 @@ package:
|
||||
- strings: ">=6.0.1 <7.0.0"
|
||||
- tailrec: ">=6.1.0 <7.0.0"
|
||||
- transformers: ">=6.0.0 <7.0.0"
|
||||
- tuples: ">=7.0.0 <8.0.0"
|
||||
- unsafe-coerce: ">=6.0.0 <7.0.0"
|
||||
test:
|
||||
main: Test.Main
|
||||
|
18
src/Pipes.Collect.purs
Normal file
18
src/Pipes.Collect.purs
Normal file
@ -0,0 +1,18 @@
|
||||
module Pipes.Collect where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Rec.Class (class MonadRec)
|
||||
import Control.Monad.ST.Class (liftST)
|
||||
import Data.Array.ST as Array.ST
|
||||
import Effect.Class (class MonadEffect, liftEffect)
|
||||
import Pipes (for) as Pipes
|
||||
import Pipes.Core (Producer)
|
||||
import Pipes.Core (runEffect) as Pipes
|
||||
|
||||
-- | Traverse a pipe, collecting into a mutable array with constant stack usage
|
||||
collectArray :: forall a m. MonadRec m => MonadEffect m => Producer a m Unit -> m (Array a)
|
||||
collectArray p = do
|
||||
st <- liftEffect $ liftST $ Array.ST.new
|
||||
Pipes.runEffect $ Pipes.for p \a -> void $ liftEffect $ liftST $ Array.ST.push a st
|
||||
liftEffect $ liftST $ Array.ST.unsafeFreeze st
|
Loading…
Reference in New Issue
Block a user