Data.Array.ST
- Package
- purescript-arrays
- Repository
- purescript/purescript-arrays
Helper functions for working with mutable arrays using the ST
effect.
This module can be used when performance is important and mutation is a local effect.
#STArray Source
data STArray :: Type -> Type -> Type
A reference to a mutable array.
The first type parameter represents the memory region which the array belongs to. The second type parameter defines the type of elements of the mutable array.
The runtime representation of a value of type STArray h a
is the same as that of Array a
,
except that mutation is allowed.
#runSTArray Source
runSTArray :: forall r a. (forall h. Eff (st :: ST h | r) (STArray h a)) -> Eff r (Array a)
DEPRECATED: Use unsafeFreeze
together with runST
instead.
Freeze a mutable array, creating an immutable array. Use this function as you would use
runST
to freeze a mutable reference.
The rank-2 type prevents the reference from escaping the scope of runSTArray
.
#emptySTArray Source
emptySTArray :: forall r h a. Eff (st :: ST h | r) (STArray h a)
Create an empty mutable array.
#pushSTArray Source
pushSTArray :: forall r h a. STArray h a -> a -> Eff (st :: ST h | r) Int
Append an element to the end of a mutable array. Returns the new length of the array.