-
-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement for-else #518
Implement for-else #518
Conversation
I'm not sure I'm a fan of this, since Rust does not have for-else itself. In most cases, you could probably handle this by calling |
I implemented for-else like Jinja does, which is not equivalent to Python's semantics. In Python the else block is executed unless a In Jinja the else block is only executed if the inner block was never entered. I guess I should implement |
de69985
to
1c22e3f
Compare
I added |
Do you actually have use cases for this syntax, or are you just aiming for feature parity with Jinja? |
For what it's worth, I technically have a use case for both :)
On one hand, I always think less code is nice. On the other hand, it only requires 1 extra set of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, sorry for the extremely slow review cycle. I've been conflicted about whether to accept this, but in the end I think it makes sense. Some minor style nits to discuss and then hopefully we can get this merged.
3d9f43f
to
18cc308
Compare
Ah, this has a conflict now. Otherwise looking good; for bonus points, also add some docs? |
This PR implements for-else statements like in Jinja. They make it easy to print an alternative message if the loop iterator was empty. E.g. ```rs {% for result in result %} <li>{{ result }}</li> {% else %} <li><em>no results</em></li> {% endfor %} ```
18cc308
to
668d74b
Compare
Thank you! I'll have a look at the book. I guess the changes of some of the older PRs need to be mentioned, too. |
This PR implements for-else statements like in Jinja. They make it easy
to print an alternative message if the loop iterator was empty. E.g.