I want to access to the case value in the case block
val a = "hello"
a match {
case "hello" | "Hi" =>
println("hello") // how can I access the right case value? Hello or Hi?
case _ =>
print("NA")
}
You can reference the matched value like so:
a match {
case str @ ("hello" | "Hi") => println(str)
case _ => print("NA")
}
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