I know in Scala you can handle multiple patterns with a single expression, is something like this possible in Elm?
l match {
case B(_) | C(_) => "B"
}
In Elm, you can only match upon one pattern at a time, unless you are pattern matching on the underscore character, which catches all.
case l of
B _ -> "B"
C _ -> "B"
...
-- or...
case l of
...
_ -> "B"
If you have something more complex that a string, it is probably best to pull it into its own function:
let
doB -> "B"
in
case l of
B _ -> doB
C _ -> doB
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With