Apologies if this has been asked before - I did a brief search and couldn't find anything.
Would it be possible to allow case-lambdas within parentheses (instead of braces) in a future version of Scala?
The idea is just to allow "(case pat (if cond)? => expr)" to mean the same as "{ case pat (if cond)? => expr }", at least when inside an argument list (but hopefully anywhere inside parentheses). So we could write things like:
Map("asd" -> 123).map(case (k, v) => (k, v + 1))
or even lose the parentheses when in a multi-argument list:
multiArgumentMethod(case (x, hd::tl) => x::tl, case (x, Nil) => x::Nil)
or whatever. For ambiguity's sake, we couldn't allow it outside of parentheses, and maybe not outside of argument lists at all (but I don't think we'd have to go that far):
val f = case (a, b) => a + b // No!
val f = (case (a, b) => a + b) // Maybe?
As far as I can see, this shouldn't be ambiguous in the grammar, but I could definitely be missing something.
Thanks,
Luke
P.S. Justification for additional syntax: I find it kind of irritating that every lambda syntax besides case-lambdas allows both paren- and brace-surrounded forms. Additionally, you can't use curly braces to surround multiple-argument-lists. This creates a nasty tension where it seems like there is no way to have consistent code style when passing arguments in Scala - sometimes you need curly braces, sometimes you need parens, which requires (the horror!) _thinking_. Obviously I would prefer to minimize thinking as much as possible (I'm sort of kidding but I have found that the extra cognitive load of all the formatting decisions you're allowed to make in Scala can be distracting, even though I appreciate the flexibility).