method from-loop

Documentation for method from-loop assembled from the following types:

class Seq

From Seq

(Seq) method from-loop

multi method from-loop(&body --> Seq:D)
multi method from-loop(&body&cond:$repeat --> Seq:D)
multi method from-loop(&body&cond&afterward --> Seq:D)

These methods create new Seq-based callbacks.

The first form produces an infinite Seq by calling &body each time a new element is requested, using the return value from &body as the item. This emulates (or implements) a loop { body } construct.

The second form calls &cond before each call to &body, and terminates the sequence if &cond returns a false value. If $repeat is set to a true value, the first call to &cond is omitted, and &body called right away. This emulates (or implements) while cond { body } and repeat { body } while cond loops.

The third form enables C-style looping by calling a third callback, &afterward, after each call to &body.