HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulestreamly-core-0.3.1Haskell2010

Streamly.Data.MutArray.Generic

Unconstrained version of Streamly.Data.MutArray module.

See the Streamly.Data.MutArray module for documentation.

Contents
  1. Setup
  2. Type
  3. Construction
  4. Appending elements
  5. Inplace mutation
  6. Random reads
  7. Conversion
  8. Streams
  9. Unfolds
  10. Stream of Arrays
  11. Size
  12. Deprecated
Synopsis

Setup

To execute the code examples provided in this module in ghci, please run the following commands first.

Example4 expressions
:mimport qualified Streamly.Data.Fold as Foldimport qualified Streamly.Data.MutArray.Generic as MutArrayimport qualified Streamly.Data.Stream as Stream

For APIs that have not been released yet.

Example1 expression
import Streamly.Internal.Data.MutArray.Generic as MutArray

Type

Construction

valueemptyOf :: MonadIO m => Int -> m (MutArray a)

emptyOf count allocates a zero length array that can be extended to hold up to count items without reallocating.

Pre-release

valuecreateOf :: MonadIO m => Int -> Fold m a (MutArray a)

createOf n folds a maximum of n elements from the input stream to an Array.

Example1 expression
createOf n = Fold.take n (MutArray.unsafeCreateOf n)

Pre-release

valuecreate :: MonadIO m => Fold m a (MutArray a)

Fold the whole input to a single array.

Same as createWith using an initial array size of arrayChunkSize bytes rounded up to the element size.

Caution! Do not use this on infinite streams.

Appending elements

valuesnoc :: MonadIO m => MutArray a -> a -> m (MutArray a)

The array is mutated to append an additional element to it. If there is no reserved space available in the array then it is reallocated to double the original size.

This is useful to reduce allocations when appending unknown number of elements.

Note that the returned array may be a mutated version of the original array.

Example1 expression
snoc = MutArray.snocWith (* 2)

Performs O(n * log n) copies to grow, but is liberal with memory allocation.

Pre-release

Inplace mutation

valueputIndex :: MonadIO m => Int -> MutArray a -> a -> m ()

O(1) Write the given element at the given index in the array. Performs in-place mutation of the array.

Example1 expression
putIndex ix arr val = MutArray.modifyIndex ix arr (const (val, ()))

Pre-release

valueunsafePutIndex :: MonadIO m => Int -> MutArray a -> a -> m ()

Write the given element to the given index of the array. Does not check if the index is out of bounds of the array.

Pre-release

valueunsafeModifyIndex :: MonadIO m => Int -> MutArray a -> (a -> (a, b)) -> m b

Modify a given index of an array using a modifier function without checking the bounds.

Unsafe because it does not check the bounds of the array.

Pre-release

Random reads

valueunsafeGetIndex :: MonadIO m => Int -> MutArray a -> m a

Return the element at the specified index without checking the bounds.

Unsafe because it does not check the bounds of the array.

Conversion

Streams

valueread :: MonadIO m => MutArray a -> Stream m a

Generates a stream from the elements of a MutArray.

Example1 expression
read = Stream.unfold MutArray.reader

Unfolds

Stream of Arrays

Size

Deprecated

valuemodifyIndexUnsafe :: MonadIO m => Int -> MutArray a -> (a -> (a, b)) -> m b

Deprecated. Please use unsafeModifyIndex instead.

Modify a given index of an array using a modifier function without checking the bounds.

Unsafe because it does not check the bounds of the array.

Pre-release

valueputIndexUnsafe :: MonadIO m => Int -> MutArray a -> a -> m ()

Deprecated. Please use unsafePutIndex instead.

Write the given element to the given index of the array. Does not check if the index is out of bounds of the array.

Pre-release

valuegetIndexUnsafe :: MonadIO m => Int -> MutArray a -> m a

Deprecated. Please use unsafeGetIndex instead.

Return the element at the specified index without checking the bounds.

Unsafe because it does not check the bounds of the array.