Implicit declarations in for comprehensions
Today’s interesting bit of Dotty news is this PR. The title — “Allow given
bindings in patterns” is a bit technical, and the example:
for given x: T <- xs
yield ... // `x` is a given here
only makes sense if you’ve been following previous Dotty changes. (In particular, the brace-free syntax that I personally hate, and the rise of given
as the likely new keyword for implicits.)
But putting it together, it’s a neat, useful enhancement that folks have been asking for for a long time now — the primary upshot is that it provides the ability to declare an implicit
value (by whatever terminology) in a for
comprehension.
I don’t expect this to be an everyday feature, but it’s going to be helpful from time to time, and it makes the language more regular in the “this seems like it ought to work” sense. It seems like a win…