Review Seq matching when porting to 2.13
Briefly

Review Seq matching when porting to 2.13
"The short-term cost to this gain is an issue under specific circumstances. If: you use pattern matching on a scala.Seq (or IndexedSeq) in 2.12 where the Seq comes from a library and you upgrade to 2.13 …then you may find your patterns no longer match at runtime. The reason is that in 2.12 your Seq is the agnostic scala.collection.Seq, but in 2.13 it’s the strong scala.collection.immutable.Seq. The library, however, may still be giving you a scala.collecton.Seq. The 2.13 default Seq is specifically immutable, which has more constraints on it that scala.collection.Seq. They won’t match in a pattern."
"Consider pattern matching on Seq handed to us in a JsArray from Play JSON: // Using "com.typesafe.play" %% "play-json" % "2.8.1" import play.api.libs.json._ def main(args: Array[String]): Unit = { // We will parse this into `JsArray(scala.collection.IndexedSeq)` val json = Json.parse(""" [ "hat", "dog" ] """) json match { case JsArray(Seq(s1, s2)) => println(s"Matched: $s1, $s2") case otherwise => println(s"Unexpected: $otherwise") } } What does this code do?"
Scala 2.13 changes scala.Seq[+A] to alias scala.collection.immutable.Seq[A], so the default Seq is immutable. Pattern matching on Seq in 2.13 uses immutable Seq extractors and therefore expects immutable implementations. Libraries may still return scala.collection.Seq or scala.collection.IndexedSeq implementations compiled against 2.12, which are not the 2.13 immutable Seq type. Pattern matches such as case JsArray(Seq(...)) can fail at runtime when the underlying sequence type differs. Developers should check the concrete Seq type returned by libraries and convert or adapt sequences to immutable.Seq when necessary.
Read at underscore.io
Unable to calculate read time
[
|
]