pow <- function(x, y) {
x^y
}
it <- i_map(pow, c(2, 3, 10), c(5, 2, 3))
as.list(it)
# Similar to the above, but because the second vector is exhausted after two
# calls to `nextElem`, the iterator is exhausted.
it2 <- i_map(pow, c(2, 3, 10), c(5, 2))
as.list(it2)
# Another similar example but with lists instead of vectors
it3 <- i_map(pow, list(2, 3, 10), list(5, 2, 3))
nextOr(it3, NA) # 32
nextOr(it3, NA) # 9
nextOr(it3, NA) # 1000
Run the code above in your browser using DataLab