HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleio-streams-1.5.2.2Haskell2010

System.IO.Streams.Vector

Vector conversions and utilities.

  • 15 values

Vector conversions

10 declarations
valuetoVector :: Vector v a => InputStream a -> IO (v a)
#

Drains an InputStream, converting it to a vector. Note that this function reads the entire InputStream strictly into memory and as such is not recommended for streaming applications or where the size of the input is not bounded or known.

ghci> is <- Streams.System.IO.Streams.fromList [(1::Int)..4]
ghci> Streams.toVector is :: IO (V.Vector Int)
fromList [1,2,3,4]

Utility

5 declarations
valuechunkVector :: Vector v a => Int -> InputStream a -> IO (InputStream (v a))
#

Splits an input stream into chunks of at most size n.

Example:

ghci> (System.IO.Streams.fromList [1..14::Int] >>= chunkVector 4 >>= System.IO.Streams.toList)
         :: IO [Vector Int]
[fromList [1,2,3,4],fromList [5,6,7,8],fromList [9,10,11,12],fromList [13,14]]
valuevectorOutputStream :: Vector v c => IO (OutputStream c, IO (v c))
#

vectorOutputStream returns an OutputStream which stores values fed into it and an action which flushes all stored values to a vector.

The flush action resets the store.

Note that this function will buffer any input sent to it on the heap. Please don't use this unless you're sure that the amount of input provided is bounded and will fit in memory without issues.

ghci> (os, flush) <- Streams.vectorOutputStream :: IO (OutputStream Int, IO (V.Vector Int))
ghci> Streams.System.IO.Streams.write (Just 1) os
ghci> Streams.System.IO.Streams.write (Just 2) os
ghci> flush
fromList [1,2]
ghci> Streams.System.IO.Streams.write (Just 3) os
ghci> Streams.System.IO.Streams.write Nothing  os
ghci> Streams.System.IO.Streams.write (Just 4) os
ghci> flush
fromList [3]