Module
Data.Array.ST.Indexed
- Package
- purescript-arrays-indexed
- Repository
- rowtype-yoga/purescript-arrays-indexed
A mutable array whose length can't change, with indices that are valid for exactly that array.
reversed :: forall a. Array a -> Array a
reversed = withArray \arr -> go (first arr) (last arr) arr
where
go :: forall s h. Maybe (Index s) -> Maybe (Index s) -> Fixed s h a -> ST h Unit
go (Just i) (Just j) arr | i < j = do
swap i j arr
go (next i arr) (prev j arr) arr
go _ _ _ = pure unit
withFixed copies an array into a fresh mutable one and brands it with
s. You only ever see it as a Fixed s h a, which can be read and
written but never grown or shrunk, so every Index s stays valid.
#replicateLike Source
replicateLike :: forall s h a b. b -> Fixed s h a -> ST h (Fixed s h b)A new mutable array as long as this one and with its brand, every element value, so an
index into one is an index into the other: a table of distances next to a graph's edges.