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

Modulestreamly-core-0.2.2Haskell2010

Streamly.Data.MutArray.Generic

Unconstrained version of Streamly.Data.MutArray module.

See the Streamly.Data.MutArray module for documentation.

  • 1 type
  • 20 values

Setup

0 declarations

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

1 declaration

Construction

5 declarations
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

1 declaration
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

4 declarations
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

valueputIndexUnsafe :: 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

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

Modify a given index of an array using a modifier function.

Pre-release

valuemodifyIndexUnsafe :: 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

2 declarations
valuegetIndexUnsafe :: 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

1 declaration

Streams

2 declarations
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

1 declaration

Size

1 declaration

Deprecated

3 declarations