Iterators
Macros
macro filter(forLoop: ForLoopStmt): untyped
-
Iterator based 'filter', runs the iterator yielding only on those that match the expression. Can be used for x in filter(y, x == 1) or for i, x in filter(y, x == 3).
Example:
let data = [10, 20, 30] for i, x in filter(data, x == 10): assert x == 10
Source Edit macro zipIter(forBody: ForLoopStmt): untyped
-
A version of zip that captures iterators as closures which can improve speed and reduce memory usage. Supports for (x, y) in zipIter(a.items, b.items) and for x, y in zipIter(a.items, b.items).
Example:
let a = [10, 20, 30] b = "abcdef" var count = 0 for (x, y) in zipIter(a.items, b.items): echo x, y # should run 3 times inc count assert count == 3
Source Edit