Skip to content

Commit

Permalink
simplify multiple map implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jan 15, 2025
1 parent feac10b commit bf978c3
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions R/map.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,19 @@ mirai_map <- function(.x, .f, ..., .args = list(), .promise = NULL, .compute = "
return(mirai_map(.x = .x, .f = .f, ..., .args = .args, .promise = .promise, .compute = .compute))
}
xilen <- dim(.x)[1L]
vec <- if (length(xilen))
vec <- if (length(xilen)) {
is_matrix <- is.matrix(.x)
lapply(
seq_len(xilen),
if (is.matrix(.x)) function(i) mirai(
.expr = do.call(.f, c(as.list(.x), .args)),
...,
.args = list(.f = .f, .x = .x[i, ], .args = .args),
.compute = .compute
) else function(i) mirai(
function(i) mirai(
.expr = do.call(.f, c(.x, .args)),
...,
.args = list(.f = .f, .x = lapply(.x, .subset2, i), .args = .args),
.args = list(.f = .f, .x = if (is_matrix) as.list(.x[i, ]) else lapply(.x, .subset2, i), .args = .args),
.compute = .compute
)
) else `names<-`(
)
} else {
`names<-`(
lapply(
.x,
function(x) mirai(
Expand All @@ -193,6 +191,7 @@ mirai_map <- function(.x, .f, ..., .args = list(), .promise = NULL, .compute = "
),
names(.x)
)
}

if (length(.promise))
if (is.list(.promise)) {
Expand Down

0 comments on commit bf978c3

Please sign in to comment.