Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added imap_vec() #1137

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading