import scala.concurrent.duration.*
import scala.concurrent.{Await, ExecutionContext, Future}
def processOption[A](opt: Option[A]): String = opt match {
case Some(v) => s"[$v]"
case None => "[]"
}
@main def main(): Unit = {
/** Generics in functions
*/
val processOptionFunction: [A] => Option[A] => String = {
[A] => (opt: Option[A]) => processOption(opt)
}
processOptionFunction(Some(1))
/** Context functions
*/
def f(x: Int)(using ExecutionContext): Future[Int] = Future { x * 100 }
val f_signature: Int => ExecutionContext ?=> Future[Int] = f
val g: ExecutionContext ?=> Int => Future[Int] = (x: Int) => Future { x + 1 }
given ExecutionContext = scala.concurrent.ExecutionContext.global
val c = for {
a <- f(2)
b <- g(4)
} yield a + b
val r = Await.result(c, 3.seconds)
println(r) // 205
}