group_map <- function(g, x, f, ..., .ptype = NULL) {
out <- vec_init(list(), length(g))
for (i in seq_along(g)) {
out[[i]] <- f(x[g[[i]]], ...)
}
vec_c(!!!out, .ptype = .ptype)
}
Most important would be to have a C++ version that would avoid allocation of intermediate vectors, assigning scalars directly into out. Probably could get away with just providing int and double versions for now.
Something like this:
Most important would be to have a C++ version that would avoid allocation of intermediate vectors, assigning scalars directly into out. Probably could get away with just providing int and double versions for now.