Fancy strings in Scala 3

PHOTO EMBED

Mon Apr 25 2022 20:16:10 GMT+0000 (UTC)

Saved by @joel113 #scala

object LowerCased:
  private def fromImpl(s: Expr[String])(using Quotes): Expr[LowerCased] =
    import quotes.reflect.*

    s.asTerm match
      case Inlined(_, _, Literal(StringConstant(str))) =>
        if LowerCased(str) == str then s
        else report.errorAndAbort(
          s"got a string which is not all lower case: $str")
      case _ => report.errorAndAbort(
        s"got a value which is not a constant string: ${s.show}")
content_copyCOPY

https://softwaremill.com/fancy-strings-in-scala-3/