As discussed here:
This would make patterns like this possible:
iex> with x when x < 2 <- 4, do: :ok
iex> with x when x > 2 <- 4, do: :ok
iex> for x when x < 2 <- 1..4, do: x
BTW, I tried to make a pull request myself, but having no experience with the Erlang side of Elixir's implementation, all the stuff going on in in elixir_exp:expand/2 is a bit too advanced for me at the moment to implement this idiomatically. However, if I can help out with writing tests or updating documentation, please let me know!
I'm wondering, shall we support guards in for though? If so, we'll have two ways for quite the same thing:
for x when x < 2 <- 1..4, do: x
# same as we have today
for x <- 1..4, x < 2, do: x
Note that the way we have today isn't real guard and accepts any expression.
Otherwise, I think we could make it consistent with with by having real guards and treating any "bare" expression as just an expression inside.
@josevalim what are your thoughts on it?
Hey @zambal, we could team-up on it if you'd like, I could ping you when initial implementation will be done.
@lexmag Yes, I like :) Please ping me when I can help.
Support guards in with (related to #4015)
@zambal ping. :)
I got working guards in for, and they are available in with but lacking documentation.
Documented in #4334.
@lexmag Sorry for missing the ping. My GitHub activity was almost non existing for the last couple of months. But awesome to see that this has been implemented in the meanwhile :)