marrow / cinje

A Pythonic and ultra fast template engine DSL.
MIT License
33 stars 0 forks source link

Permit list comprehension–like filtering of for loops. #29

Open amcgregor opened 5 years ago

amcgregor commented 5 years ago

Where currently you require multiple lines with explicit flow control statements:

: for item in items
    : if item % 2 == 0
        : continue
    : end

Permit inclusion of filtering conditions (one or more) in the form:

: for item in items if item % 2

There are several avenues for translation to plain Python for these. Unwrap and reconstruct the multiple-line form, or alternatively wrap in a generator comprehension:

for item in (i for i in items if item % 2):