I'm paginating through an API and looking for something like map_while
, but I cannot find the appropriate function in purrr. map_if
is a no-go because I need to know the result of the computation during the loop.
Here are the two patterns I'm curious to replace:
Pattern 1: for loop + break
for (i in seq_along(x)) {
## do something ##
if (something) break
}
Pattern 2: while loop
cond <- TRUE
while(cond) {
## do something ##
if (something) {
cond <- FALSE
}
}