i_map {iterors} | R Documentation |
Iterator that applies a given function to several iterables concurrently.
Description
Constructs an iterator that computes the given function f
using the
arguments from each of the iterables given in ...
.
Usage
i_map(f, ...)
Arguments
f |
a function |
... |
multiple arguments to iterate through in sequence |
Details
The iterator returned is exhausted when the shortest iterable in ...
is exhausted. Note that i_map
does not recycle arguments as
Map
does.
The primary difference between i_starmap
and
i_map
is that the former expects an iterable object
whose elements are already grouped together, while the latter case groups the
arguments together before applying the given function. The choice is a matter
of style and convenience.
Value
iterator that returns the values of object
along with the
index of the object.
Examples
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
[Package iterors version 1.0 Index]