Scala3 unapply breaks Play Framework's form mappings?

Cross-posting Form mappings in Scala3 - CaseClass.unapply no longer usable? · playframework · Discussion #12292 · GitHub

Play framework’s form handling makes heavy use of the CaseClass.unapply method and depends on its signature being CaseClass => Option[(...)].

Scala 3’s change to the unapply method’s signature breaks this style of usage, since the unapply method now just returns the case class instance instead of an option of a tuple:

object Foo {
  def unapply(foo: Foo): Option[(...)] = ... // <- Scala 2
  def unapply(foo: Foo): Foo = foo // <- Scala 3

Any suggestions for how to proceed here? Any pointers on how to write a macro?

1 Like

You can take a look at Slick’s mapTo macro.

Or you could try just doing something like (X.unapply _).andThen(Some(_)). (Not sure if the underscore and parentheses are necessary in Scala 3.)

1 Like