-
Notifications
You must be signed in to change notification settings - Fork 195
Description
Currently, if you assign a loop to something, or treat it as an expression the result of each iteration is accumulated into an array.
This is very similar to comprehensions, but if the result of an iteration is nil then it is not added to the array.
This makes something like this possible:
my_numbers = {1,2,3,4,5,6}
odds = for x in *my_numbers
if x % 2 == 1 then xThe obvious downside is that these two things are not the same thing:
out = for x in y
x
out = [x for x in y]Since making this decision I've added the continue statement. It works with loop expressions, so the nil check can be done explicitly:
odds = for x in *my_numbers
continue unless x % 2 == 1
xI think it's better to be explicit in cases like this. Therefore I plan to remove this nil check in the loop format.
This is a backwards incompatible change. I've been going through some of my old code and it's kind of annoying finding instances of loops that need to be updated. That's why I'd like some feedback. Maybe this change is not worth it.