Skip to content
/ eval Public

Eval evaluates Scala 3 code. Why parse JSON when you can load case classes?

Notifications You must be signed in to change notification settings

eed3si9n/eval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eval

Eval evaluates Scala 3 code.

Example Usage

In your build.sbt type this or similar:

ThisBuild / scalaVersion := "3.3.1"
libraryDependencies += ("com.eed3si9n.eval" % "eval" % "0.3.0").cross(CrossVersion.full)
Compile / fork := true

In your Main.scala type this or similar:

package example

import com.eed3si9n.eval.Eval

case class ServerConfig(port: Int)

@main def main(): Unit =
  val x = Eval[ServerConfig](
    "example.ServerConfig(port = 8080)")
  println(x.port)

Run in sbt like so:

sbt:eval> run
[info] compiling 1 Scala source to target/scala-3.3.1/classes ...
[info] running (fork) example.main
[info] 8080

This shows that the string example.ServerConfig(port = 8080) was evaluated as a Scala code, and became available to the main function as an instantiated case class.

More examples here: https://eed3si9n.com/eval/

About

Eval evaluates Scala 3 code. Why parse JSON when you can load case classes?

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages