Last active
September 11, 2024 02:13
-
-
Save dmgcodevil/3a78c63c6960430a47f9092ef3a6593e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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