Open jhellerstein opened 13 years ago
A pattern using the "with" construct introduced in 2f9c6e580b4ff065ea7d helps a bit, by forcing all branches of the conditional to appear together. Suppose we have:
yay <= foo { |t| t if ruby_predicate(t) }
boo <= foo { |t| t unless ruby_predicate(t) }
That's readable, but there's the reasonable concern that the two rules could get separated in the code and still mean the same thing.
We could instead write
with :outcome <= foo { |t| [t, ruby_predicate(t)] }, begin
yay <= outcome { |o| o[0] if o[1] }
boo <= outcome { |o| o[0] unless o[1] }
end
Here, the two rules have to stay together inside the scope of with
.
It'd still be nice to have more syntactic sugar.
Or perhaps nested rules?
From the Syntax-Wishlist wiki:
Currently we achieve this by mutually-exclusive predicates buried inside multiple rule bodies. This example has two rules. The 1st rule has two cases within a single rule, which works because they share a head. The second rule happens to be the "else" of the first rule, with a different head.