Module
Data.Array.Indexed
- Package
- purescript-arrays-indexed
- Repository
- rowtype-yoga/purescript-arrays-indexed
Arrays branded with a type s, and indices that are valid for exactly
that array.
smoothed :: Array Number -> Array Number
smoothed signal = withIndexed signal \xs ->
toArray $ xs # mapWithIndex \i x -> case next i xs of
Just j -> (x + at j xs) / 2.0
Nothing -> x
withIndexed gives the array a brand s that nothing else shares. An
Index s can only come from that array, so at needs no Maybe.
#withIndexed Source
withIndexed :: forall a r. Array a -> (forall s. Indexed s a -> r) -> rBrands an array. The brand can't leave the function you pass.