-
Notifications
You must be signed in to change notification settings - Fork 72
Closed
Labels
featurea feature request or enhancementa feature request or enhancement
Description
Need to benchmark the two strategies: in the first we just put in a list and then vec_c() at the end; in the second we assume that the type is mostly stable so we can create the space for output in the beginning, and only occasionally change.
vec_map <- function(.x, .f, ..., .ptype = NULL) {
.x <- lapply(.x, .f, ...)
vec_c(!!!.x, .ptype = .ptype)
}
vec_map <- function(.x, .f, ..., .ptype = NULL) {
first <- .x[[1]]
first_out <- .f(.x, ...)
out <- vec_na(first_out, vec_size(.x))
vec_slice(out, 1) <- first_out
for (i in seq2(2, vec_size(.x))) {
outi <- .f(vec_slice(x, i), ...)
if (vec_is(outi, out)) {
# change type
}
vec_slice(out, i) <- outi
}
out
}Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancement