diff --git a/CHANGELOG.md b/CHANGELOG.md index b10a5ee..1cdcadd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ New features: Bugfixes: Other improvements: +- Use more efficient implementation for `mapWithIndex` (#233 by @JordanMartinez) ## [v7.1.0](https://github.com/purescript/purescript-arrays/releases/tag/v7.1.0) - 2022-08-06 diff --git a/src/Data/Array.purs b/src/Data/Array.purs index 866cc30..fdd3223 100644 --- a/src/Data/Array.purs +++ b/src/Data/Array.purs @@ -143,6 +143,7 @@ import Data.Array.ST as STA import Data.Array.ST.Iterator as STAI import Data.Foldable (class Foldable, traverse_) import Data.Foldable as F +import Data.FunctorWithIndex as FWI import Data.Maybe (Maybe(..), maybe, isJust, fromJust, isNothing) import Data.Traversable (sequence, traverse) import Data.Tuple (Tuple(..), fst, snd) @@ -738,8 +739,7 @@ catMaybes = mapMaybe identity -- | ``` -- | mapWithIndex :: forall a b. (Int -> a -> b) -> Array a -> Array b -mapWithIndex f xs = - zipWith f (range 0 (length xs - 1)) xs +mapWithIndex = FWI.mapWithIndex -- | Change the elements at the specified indices in index/value pairs. -- | Out-of-bounds indices will have no effect.