Constructs an iterator that removes runs of repeated elements from the underlying iterator. Order of the elements is maintained. Only the element just seen is remembered for determining whether to drop.
Arguments
- object
an iterable object
- cmp
A function to use for comparison.
- ...
passed along to
iteror(object, ...)
Examples
it <- i_chain(rep(1,4), rep(2, 5), 4:7, 2)
it_i_unique <- idedup(it)
as.list(it_i_unique) # 1 2 4 5 6 7 2
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 4
#>
#> [[4]]
#> [1] 5
#>
#> [[5]]
#> [1] 6
#>
#> [[6]]
#> [1] 7
#>
#> [[7]]
#> [1] 2
#>
it2 <- iteror(c('a', 'a', "A", 'a', 'a', "V"))
i_dedupe <- idedup(it2)
as.list(idedup) # a A a V
#> $object
#>
#>
#> $cmp
#> identical
#>
#> $...
#>
#>
#> [[4]]
#> {
#> object <- iteror(object, ...)
#> prev_elem <- NULL
#> first_seen <- FALSE
#> nextOr_ <- function(or) {
#> repeat {
#> elem <- nextOr(object, return(or))
#> if (!first_seen || !cmp(elem, prev_elem)) {
#> first_seen <<- TRUE
#> prev_elem <<- elem
#> return(elem)
#> }
#> prev_elem <<- elem
#> }
#> }
#> iteror_internal(nextOr_)
#> }
#>