Skip to content

Commit 97cd3f7

Browse files
Use FunctorWithIndex.mapWithIndex (#233)
* Use FunctorWithIndex.mapWithIndex * Add changelog entry
1 parent bb1b821 commit 97cd3f7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ New features:
1111
Bugfixes:
1212

1313
Other improvements:
14+
- Use more efficient implementation for `mapWithIndex` (#233 by @JordanMartinez)
1415

1516
## [v7.1.0](https://github.com/purescript/purescript-arrays/releases/tag/v7.1.0) - 2022-08-06
1617

src/Data/Array.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ import Data.Array.ST as STA
143143
import Data.Array.ST.Iterator as STAI
144144
import Data.Foldable (class Foldable, traverse_)
145145
import Data.Foldable as F
146+
import Data.FunctorWithIndex as FWI
146147
import Data.Maybe (Maybe(..), maybe, isJust, fromJust, isNothing)
147148
import Data.Traversable (sequence, traverse)
148149
import Data.Tuple (Tuple(..), fst, snd)
@@ -738,8 +739,7 @@ catMaybes = mapMaybe identity
738739
-- | ```
739740
-- |
740741
mapWithIndex :: forall a b. (Int -> a -> b) -> Array a -> Array b
741-
mapWithIndex f xs =
742-
zipWith f (range 0 (length xs - 1)) xs
742+
mapWithIndex = FWI.mapWithIndex
743743

744744
-- | Change the elements at the specified indices in index/value pairs.
745745
-- | Out-of-bounds indices will have no effect.

0 commit comments

Comments
 (0)