i_unique {iterors} | R Documentation |
Iterator that extracts the unique elements from an iterable object
Description
Constructs an iterator that extracts each unique element in turn from an
iterable object
. Order of the elements is maintained. This function is
an iterator analogue to unique.
Usage
i_unique(object, digest = rlang::hash, ...)
Arguments
object |
an iterable object |
digest |
Optionally specify a custom hash function
(e.g. |
... |
Extra arguments are forwarded to iteror. |
Details
NOTE: In order to determine whether an element is unique, a list of previous unique elements is stored. In doing so, the list can potentially become large if there are a large number of unique elements.
Value
an iterator that returns only the unique elements from
object
See Also
i_dedupe
Examples
it <- i_chain(rep(1, 4), rep(2, 5), 4:7, 2)
as.list(i_unique(it)) # 1 2 4 5 6 7
it2 <- iterators::iter(c('a', 'a', "A", "V"))
as.list(i_unique(it2)) # a A V
x <- as.character(gl(5, 10))
it_unique <- i_unique(x)
as.list(it_unique) # 1 2 3 4 5
[Package iterors version 1.0 Index]