Skip to content

Commit

Permalink
added imap_vec() (#1137)
Browse files Browse the repository at this point in the history
Fixes #1084
  • Loading branch information
edavidaja authored Aug 15, 2024
1 parent 770bbfe commit d022c4e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export(imap_dfr)
export(imap_int)
export(imap_lgl)
export(imap_raw)
export(imap_vec)
export(imodify)
export(insistently)
export(invoke)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# purrr (development version)

* Added `imap_vec()` (#1084)
* `list_transpose()` inspects all elements to determine the correct
template if it's not provided by the user (#1128, @krlmlr).

Expand Down
7 changes: 7 additions & 0 deletions R/imap.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ imap_dbl <- function(.x, .f, ...) {
map2_dbl(.x, vec_index(.x), .f, ...)
}

#' @rdname imap
#' @export
imap_vec <- function(.x, .f, ...) {
.f <- as_mapper(.f, ...)
map2_vec(.x, vec_index(.x), .f, ...)
}


#' @export
#' @rdname imap
Expand Down
3 changes: 3 additions & 0 deletions man/imap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-imap.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test_that("atomic vector imap works", {
expect_length(imap_chr(x, paste), 3)
expect_equal(imap_int(x, ~ .x + as.integer(.y)), x * 2)
expect_equal(imap_dbl(x, ~ .x + as.numeric(.y)), x * 2)
expect_equal(imap_vec(x, ~ .x + as.numeric(.y)), x * 2)
})

test_that("iwalk returns invisibly", {
Expand Down

0 comments on commit d022c4e

Please sign in to comment.