Skip to content

Instantly share code, notes, and snippets.

@dmgcodevil
Last active September 11, 2024 02:13
Show Gist options
  • Select an option

  • Save dmgcodevil/3a78c63c6960430a47f9092ef3a6593e to your computer and use it in GitHub Desktop.

Select an option

Save dmgcodevil/3a78c63c6960430a47f9092ef3a6593e to your computer and use it in GitHub Desktop.
object Main {
trait Executor {}
trait Context {
def data: String
}
type IO[T] = Executor ?=> T
type Result[T] = Context ?=> IO[T]
class Downstream {
def fetch(): Result[String] = {
val c = summon[Context]
s"response ${c.data}"
}
}
class Service {
val downstream = new Downstream()
def execute(): Result[String] = {
val c = summon[Context]
downstream.fetch()(using
new Context {
override def data: String = s"${c.data}-service"
}
)
}
}
def main(args: Array[String]): Unit = {
given e: Executor = new Executor {}
given c: Context = new Context {
def data: String = "entry-point"
}
val svc = Service()
println(svc.execute())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment