Skip to contents

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, ...)

Arguments

x

bandicoot_oop object.

...

Additional arguments needed for building an iterator.

Value

An iterator.

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