Are internal iterators still possible?
Edit: In fact, this is true of any language with higher-order functions. For example, this is how you'd define a Rust-style internal iterator for lists in Racket scheme:
(define (iter l f)
(when (and (pair? l) (f (car l)))
(iter (cdr l) f)))
And how you'd use it: ;; displays elements of the list, up to and including the first one >= 3
(iter '(1 2 3 4) (lambda (x) (display x) (< x 3))) do tree.visit_each_leaf |leaf| {
// ... do things with leaf ...
if some_continuation_condition { true } else { false }
}
(The last line is the replacement for what would be currently written `if !some_continuation_condition { break }` with the `for` sugar.)