It would be nice if we could mark the values that have been matched in a pattern as implicit. Not having this ability means that we need to reassign values that have just been pattern matched to a new implicit val to make them available in the implicit scope of the case.
Here’s a simple example. Say I want the boolean to be available in the implicit scope of the match, I have no choice but to do this:
val seq = (123,"Words",true)
seq match {
case (a: Int,b: String,c: Boolean) => {
implicit val c2 = c
implicitly[Boolean]
println("Works")
}
}
This seems repetitive and unnecessary. It would be nice if we could do something like this
val seq = (123,"Words",true)
seq match {
case (a: Int,b: String,implicit c: Boolean) => {
implicitly[Boolean]
println("Would be nice if this worked")
}
}
Here’s a more involved and more realistic scenario on scastie that actually gave me the idea
And here’s the original issue from github
It seems we can already do this on parameters to lambda functions, so why not add it to pattern matching as well?