A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nicolasstucki/scala-days-2023/ below:

GitHub - nicolasstucki/scala-days-2023

Scala Days 2023 - Implementing a Macro in Scala 3

This is a normal sbt project. You can compile code with sbt compile, test it with sbt test, and sbt console will start a Scala 3 REPL.

type Json = JsonObject | JsonArray | Double | String | Boolean | Null
Macro JSON string interpolation

The string interpolator json defined in JsonStringContext.scala provides shows how to implement the interpolator apply and unapply with macros.

Crate refined JSON with an interpolator
val user = json"""{
    "firstName": "John",
    "lastName": "Doe"
  }"""
val bool = json"true"
val account = json"""{
    "user": $user,
    "active": $bool
}"""

where the type of account is refined to

account: JsonObject {
  val user: JsonObject {
    val firstName: String
    val lastName:String
  }
  val active: Boolean
}
Extracting refined JSON with an interpolator
(account: Json) match
  case json"""{ "user": $x, "active": true }""" => println(x + " is active")
  case _ =>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4