clone {peruse}R Documentation

clone

Description

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.

Usage

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)
current(other) == current(it) # false

it2 <- clone(other, n = 5)
yield_next(it2)
it2$initial$n  # 5

[Package peruse version 0.3.1 Index]