Skip to contents

Constructs an iterator that traverses each given iterable in a roundrobin order. That is, the iterables are traversed in an alternating fashion such that the each element is drawn from the next iterable. If an iterable has no more available elements, it is skipped, and the next element is taken from the next iterable having available elements.

Usage

i_roundrobin(...)

Arguments

...

multiple arguments to iterate through in roundrobin sequence

Value

iterator that alternates through each argument in roundrobin sequence

Examples

it <- iteror(c("A", "B", "C"))
it2 <- iteror("D")
it3 <- iteror(c("E", "F"))
as.list(i_roundrobin(it, it2, it3)) # A D E B F C
#> [[1]]
#> [1] "A"
#> 
#> [[2]]
#> [1] "D"
#> 
#> [[3]]
#> [1] "E"
#> 
#> [[4]]
#> [1] "B"
#> 
#> [[5]]
#> [1] "F"
#> 
#> [[6]]
#> [1] "C"
#> 

it_rr <- i_roundrobin(1:3, 4:5, 7:10)
as.list(it_rr) # 1 4 7 2 5 8 3 9 10
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 4
#> 
#> [[3]]
#> [1] 7
#> 
#> [[4]]
#> [1] 2
#> 
#> [[5]]
#> [1] 5
#> 
#> [[6]]
#> [1] 8
#> 
#> [[7]]
#> [1] 3
#> 
#> [[8]]
#> [1] 9
#> 
#> [[9]]
#> [1] 10
#>