Clone an Iterator, making an exact copy that can then be modified separately. This is a simple wrapper around rlang::env_clone(). Optionally, override old initial parameters.

clone(iter, ...)

Arguments

iter

an Iterator object

...

optionally override the $initial parameters in iter

Value

a copy of the Iterator passed as a parameter

Examples

it <- Iterator({m <- m + n}, list(m = 0, n = 1), m) other <- clone(it) yield_next(it)
#> [1] 1
current(other) == current(it) # false
#> [1] FALSE
it2 <- clone(other, n = 5) yield_next(it2)
#> [1] 5
it2$initial$n # 5
#> [1] 5