From 8d2ad6e4d76f0c0fef5022c96be24d44c94494cb Mon Sep 17 00:00:00 2001 From: edavidaja Date: Thu, 15 Aug 2024 10:29:05 -0700 Subject: [PATCH] added imap_vec() fixes #1084 --- NAMESPACE | 1 + NEWS.md | 2 ++ R/imap.R | 7 +++++++ man/imap.Rd | 3 +++ 4 files changed, 13 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index e754bc4a..bb906a65 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 636668d4..b1f038c2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # purrr (development version) +* Added `imap_vec()` (#1084) + # purrr 1.0.2 * Fixed valgrind issue. diff --git a/R/imap.R b/R/imap.R index fa1d9e52..6db2d046 100644 --- a/R/imap.R +++ b/R/imap.R @@ -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, ...) + map_vec(.x, vec_index(.x), .f, ...) +} + #' @export #' @rdname imap diff --git a/man/imap.Rd b/man/imap.Rd index ae081b01..b453d245 100644 --- a/man/imap.Rd +++ b/man/imap.Rd @@ -6,6 +6,7 @@ \alias{imap_chr} \alias{imap_int} \alias{imap_dbl} +\alias{imap_vec} \alias{iwalk} \title{Apply a function to each element of a vector, and its index} \usage{ @@ -19,6 +20,8 @@ imap_int(.x, .f, ...) imap_dbl(.x, .f, ...) +imap_vec(.x, .f, ...) + iwalk(.x, .f, ...) } \arguments{