String interpolation in pattern matching


#1

There are interesting discussion:
-Better number literals (Better number literals)
-Bigdecimal literal (Bigdecimal literal)

We also widely use custom types in our framework (to provide 3vl for better database integration):
-date
-Number
-String

The best way to construct these types is string interpolation.

I agree that:

I think, if there is the ability to use string interpolation in pattern matching the most difficulties will be solved.

If support for “unapply” is implemented:

implicit class ExtendedLongHelper(val sc: StringContext) extends AnyVal {
  def el(args: Any*): Long = ???
  def unapply(args: Any*):Boolean = ???
}

There will be ability to write:

val l = el”1000_4332_24”
l match {
  case el”1000_4332_24” => println( “good :)” )
}

#2

That ability already exists, see https://docs.scala-lang.org/sips/string-interpolation.html


#3

Thank you.

Would it be posible to add this abiity to Scala specification syntax summary?
https://scala-lang.org/files/archive/spec/2.12/13-syntax-summary.html

It is a big suprise, when any standard ability works if it is absence in syntax summary.


#4

I agree that taking SIPs as endless supplements to the spec is confusing.


#5

Pull requests merging past SIPs into the Scala spec would be exceedingly welcome.


#6

#7

Seth is exceedingly welcoming.