Support for something like Rust if-let #22285
Replies: 5 comments
-
This reminds me dart-lang/language#4205 |
Beta Was this translation helpful? Give feedback.
-
Similar discussion happened in F# fsharp/fslang-suggestions#705 |
Beta Was this translation helpful? Give feedback.
-
Maybe use the function |
Beta Was this translation helpful? Give feedback.
-
What's the benefit over: myOption match
case Some(v) if v.xyz =>
...
case None => ? |
Beta Was this translation helpful? Give feedback.
-
There's been a (pre-)pre-SIP on this topic with a lengthy explanations of the motivations for such a feature: https://contributors.scala-lang.org/t/pre-sip-s-improving-the-expressiveness-of-conditional-control-flow/6488 There are plans to work on a proper SIP in the near future. Any help is welcome obviously. |
Beta Was this translation helpful? Give feedback.
-
Hi team,
I'm very new here, so apologies if I didn't provide enough details. I'm wondering if you have given any thoughts around supporting something like rust if let
The basic idea is to allow for destructuring in if condition and bind everything in the if scope, you can already do that with
match
of course, but I often find myself only interested in a single case of an enum for example while the remaining cases won't need special handling for them.This is already supported in different scala constructs like for comprehensions and would be nice to do something like
instead of
It gets complicated if you want to use v further in the condition though
Beta Was this translation helpful? Give feedback.
All reactions