Add implict support when do extraction in Pattern matching?

    override def receive: Receive = {
      case DnsQuestionPreInjection(resolver, inject, timeout) =>
        implicit val tmout = timeout
        val question = inject(nextId())
        val forwardAnswerTo = sender()
        val result = (resolver ? question).mapTo[Answer]

        result.onComplete {
          case Success(answer) => forwardAnswerTo ! answer
          case Failure(_)      => resolver ! DropRequest(question.id)
        }(ExecutionContexts.parasitic)
    }

from :fix: Refactor future callbacks in AsyncDnsResolver by leviramsey · Pull Request #31906 · akka/akka · GitHub

I think it would be great if can written in

      case DnsQuestionPreInjection(resolver, inject, implicit timeout) =>

Then the implicit val tmout = timeout is not needed anymore.

1 Like

That is available for given.

scala> case class C(i: Int)
// defined case class C

scala> val c = C(42)
val c: C = C(42)

scala> c match { case C(given Int) => println(summon[Int]) }
42
5 Likes