Iteror that chains multiple arguments together into a single iterator
Source:R/i_concat.R
, R/ichain.R
i_chain.Rd
i_concat(obj)
takes an iterable that returns
iterables, and chains together all inner values of iterables into
one iterator. Analogous to unlist(recursive=FALSE)
.
i_chain
for iterators is analogous to c()
on vectors. i_chain
constructs an iteror that returns elements from the first
argument until it is exhausted, then elements from the next
argument, and so on until all arguments have been exhausted.
Examples
it <- i_chain(1:3, 4:5, 6)
as.list(it)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
#>
#> [[4]]
#> [1] 4
#>
#> [[5]]
#> [1] 5
#>
#> [[6]]
#> [1] 6
#>
it2 <- i_chain(1:3, levels(iris$Species))
as.list(it2)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
#>
#> [[4]]
#> [1] "setosa"
#>
#> [[5]]
#> [1] "versicolor"
#>
#> [[6]]
#> [1] "virginica"
#>