Skip to content

Commit

Permalink
Rename std.array.imap to std.array.map_with_index (tweag#1829)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkleen authored Feb 29, 2024
1 parent 20809d3 commit 27d7185
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions core/stdlib/std.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -771,17 +771,17 @@
(fun i => f (std.array.at i xs) (std.array.at i ys))
(std.number.min (std.array.length xs) (std.array.length ys)),

imap
map_with_index
: forall a b. (Number -> a -> b) -> Array a -> Array b
| doc m%"
Applies a function to every element in the given array while passing
its (0-based) index. That is,
`imap f [ x1, x2, ... ]` is `[ f 0 x1, f 1 x2, ... ]`.
`map_with_index f [ x1, x2, ... ]` is `[ f 0 x1, f 1 x2, ... ]`.

# Examples

```nickel
std.array.map (fun i x => i + x + 1) [ 1, 2, 3 ] =>
std.array.map_with_index (fun i x => i + x + 1) [ 1, 2, 3 ] =>
[ 2, 4, 6 ]
```
"%
Expand Down
2 changes: 1 addition & 1 deletion core/tests/integration/inputs/core/arrays.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ let {check, ..} = import "../lib/assert.ncl" in
std.array.zip_with (*) [1, 2] [4, 5, 6] == [4, 10],
std.array.zip_with (-) [1, 2, 3] [4, 5] == [-3, -3],

std.array.imap (+) [1, 2, 3] == [1, 3, 5],
std.array.map_with_index (+) [1, 2, 3] == [1, 3, 5],
]
|> check

0 comments on commit 27d7185

Please sign in to comment.