S3 method of building an iterator of a
bandicoot_oop
object
Source: R/oop_s3.R
iter.bandicoot_oop.Rd
This function builds an iterator using the ..iter..()
method.
If it is not applicable, error will be raised.
Usage
# S3 method for bandicoot_oop
iter(x, ...)
Examples
COMPANY <- new_class(class_name = "COMPANY")
company <- COMPANY$instantiate
register_method(COMPANY,
..init.. = function(name, age) {
self$name <- name
self$age <- age
})
register_method(COMPANY,
..iter.. = function(...) {
split(data.frame(name = self$name, age = self$age),
1:length(self$name))
})
good_company <- company(c("patrick", "james"),
c(33, 34))
for (person in iter(good_company)) {
print(person)
}
#> name age
#> 1 patrick 33
#> name age
#> 2 james 34