Skip to content

Instantly share code, notes, and snippets.

@p-pavel
Last active May 19, 2024 13:02
Show Gist options
  • Save p-pavel/378b20b374f0be8c98268c62be05733c to your computer and use it in GitHub Desktop.
Save p-pavel/378b20b374f0be8c98268c62be05733c to your computer and use it in GitHub Desktop.
My take on how sbt syntax api can be implemented in pure scala 3
trait PseudoSbt:
type Setting[+_]
type Key[+_]
type Project
/** context to extract value of type A from Setting[A]*/
type ValueExtractor
/** Location in source file to be used to track definitions*/
type Location
extension [A](s: Key[A])(using ValueExtractor)
/** Should be an inline providing location of definition*/
def value: A
def :=(v: ValueExtractor ?=> A): Setting[A]
type File
extension (f: File)
def /(s: String): File
def baseDirectory: Key[File]
def srcDirectory: Key[File]
extension (p: Project)
def settings(ss: Setting[Any]*): Project
def in(baseDir: File): Project
def project: Project
val example: Setting[File] =
srcDirectory := baseDirectory.value / "src"
end PseudoSbt
trait PseudoSbt:
type Setting[+_]
type Key[+_]
type Project
/** context to extract value of type A from Setting[A]*/
type ValueExtractor
/** Location in source file to be used to track definitions*/
type Location
extension [A](s: Key[A])(using ValueExtractor)
/** Should be an inline providing location of definition*/
def value: A
def :=(v: ValueExtractor ?=> A): Setting[A]
type File
extension (f: File)
def /(s: String): File
def baseDirectory: Key[File]
def srcDirectory: Key[File]
extension (p: Project)
def settings(ss: Setting[Any]*): Project
def in(baseDir: File): Project
def project: Project
val example: Setting[File] =
srcDirectory := baseDirectory.value / "src"
end PseudoSbt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment