|
| 1 | +## Module Data.Array.ST |
| 2 | + |
| 3 | +Helper functions for working with mutable arrays using the `ST` effect. |
| 4 | + |
| 5 | +This module can be used when performance is important and mutation is a local effect. |
| 6 | + |
| 7 | +#### `STArray` |
| 8 | + |
| 9 | +``` purescript |
| 10 | +data STArray :: * -> * -> * |
| 11 | +``` |
| 12 | + |
| 13 | +A reference to a mutable array. |
| 14 | + |
| 15 | +The first type parameter represents the memory region which the array belongs to. |
| 16 | +The second type parameter defines the type of elements of the mutable array. |
| 17 | + |
| 18 | +The runtime representation of a value of type `STArray h a` is the same as that of `[a]`, |
| 19 | +except that mutation is allowed. |
| 20 | + |
| 21 | +#### `Assoc` |
| 22 | + |
| 23 | +``` purescript |
| 24 | +type Assoc a = { value :: a, index :: Int } |
| 25 | +``` |
| 26 | + |
| 27 | +An element and its index |
| 28 | + |
| 29 | +#### `runSTArray` |
| 30 | + |
| 31 | +``` purescript |
| 32 | +runSTArray :: forall a r. (forall h. Eff (st :: ST h | r) (STArray h a)) -> Eff r (Array a) |
| 33 | +``` |
| 34 | + |
| 35 | +Freeze a mutable array, creating an immutable array. Use this function as you would use |
| 36 | +`runST` to freeze a mutable reference. |
| 37 | + |
| 38 | +The rank-2 type prevents the reference from escaping the scope of `runSTArray`. |
| 39 | + |
| 40 | +#### `emptySTArray` |
| 41 | + |
| 42 | +``` purescript |
| 43 | +emptySTArray :: forall a h r. Eff (st :: ST h | r) (STArray h a) |
| 44 | +``` |
| 45 | + |
| 46 | +Create an empty mutable array. |
| 47 | + |
| 48 | +#### `thaw` |
| 49 | + |
| 50 | +``` purescript |
| 51 | +thaw :: forall a h r. Array a -> Eff (st :: ST h | r) (STArray h a) |
| 52 | +``` |
| 53 | + |
| 54 | +Create a mutable copy of an immutable array. |
| 55 | + |
| 56 | +#### `freeze` |
| 57 | + |
| 58 | +``` purescript |
| 59 | +freeze :: forall a h r. STArray h a -> Eff (st :: ST h | r) (Array a) |
| 60 | +``` |
| 61 | + |
| 62 | +Create an immutable copy of a mutable array. |
| 63 | + |
| 64 | +#### `peekSTArray` |
| 65 | + |
| 66 | +``` purescript |
| 67 | +peekSTArray :: forall a h r. STArray h a -> Int -> Eff (st :: ST h | r) (Maybe a) |
| 68 | +``` |
| 69 | + |
| 70 | +Read the value at the specified index in a mutable array. |
| 71 | + |
| 72 | +#### `pokeSTArray` |
| 73 | + |
| 74 | +``` purescript |
| 75 | +pokeSTArray :: forall a h r. STArray h a -> Int -> a -> Eff (st :: ST h | r) Boolean |
| 76 | +``` |
| 77 | + |
| 78 | +Change the value at the specified index in a mutable array. |
| 79 | + |
| 80 | +#### `pushSTArray` |
| 81 | + |
| 82 | +``` purescript |
| 83 | +pushSTArray :: forall a h r. STArray h a -> a -> Eff (st :: ST h | r) Int |
| 84 | +``` |
| 85 | + |
| 86 | +Append an element to the end of a mutable array. |
| 87 | + |
| 88 | +#### `pushAllSTArray` |
| 89 | + |
| 90 | +``` purescript |
| 91 | +pushAllSTArray :: forall a h r. STArray h a -> Array a -> Eff (st :: ST h | r) Int |
| 92 | +``` |
| 93 | + |
| 94 | +Append the values in an immutable array to the end of a mutable array. |
| 95 | + |
| 96 | +#### `spliceSTArray` |
| 97 | + |
| 98 | +``` purescript |
| 99 | +spliceSTArray :: forall a h r. STArray h a -> Int -> Int -> Array a -> Eff (st :: ST h | r) (Array a) |
| 100 | +``` |
| 101 | + |
| 102 | +Remove and/or insert elements from/into a mutable array at the specified index. |
| 103 | + |
| 104 | +#### `toAssocArray` |
| 105 | + |
| 106 | +``` purescript |
| 107 | +toAssocArray :: forall a h r. STArray h a -> Eff (st :: ST h | r) (Array (Assoc a)) |
| 108 | +``` |
| 109 | + |
| 110 | +Create an immutable copy of a mutable array, where each element |
| 111 | +is labelled with its index in the original array. |
| 112 | + |
| 113 | + |
0 commit comments