generate_abc <- generator(function() for (x in letters[1:3]) yield(x))
abc <- generate_abc()
# Collect 1 element:
collect(abc, n = 1)
# Collect all remaining elements:
collect(abc)
# With exhausted iterators collect() returns an empty list:
collect(abc)
# With loop() you can use `for` loops with iterators:
abc <- generate_abc()
loop(for (x in abc) print(x))
Run the code above in your browser using DataLab