Skip to content

Commit

Permalink
minor api improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Feb 27, 2024
1 parent 5d0d88f commit e86330e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 16 additions & 14 deletions kyo-core/shared/src/main/scala/kyo/envs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ final class Envs[E] private[kyo] (using private val tag: Tag[?])
val get: E < Envs[E] =
suspend(Input.asInstanceOf[Env[E]#Value[E]])

def run[T, S](e: E)(v: T < (Envs[E] & S))(using f: Flat[T < (Envs[E] & S)]): T < S =
given Handler[Env[E]#Value, Envs[E], Any] =
new Handler[Env[E]#Value, Envs[E], Any]:
def pure[U: Flat](v: U) = v
def apply[U, V: Flat, S2](
m: Env[E]#Value[U],
f: U => V < (Envs[E] & S2)
): V < (S2 & Envs[E]) =
m match
case Input =>
f(e.asInstanceOf[U])
case _ =>
f(m.asInstanceOf[U])
handle[T, Envs[E] & S, Any](v).asInstanceOf[T < S]
def run[T, S](e: E < S)(v: T < (Envs[E] & S))(using f: Flat[T < (Envs[E] & S)]): T < S =
e.map { e =>
given Handler[Env[E]#Value, Envs[E], Any] =
new Handler[Env[E]#Value, Envs[E], Any]:
def pure[U: Flat](v: U) = v
def apply[U, V: Flat, S2](
m: Env[E]#Value[U],
f: U => V < (Envs[E] & S2)
): V < (S2 & Envs[E]) =
m match
case Input =>
f(e.asInstanceOf[U])
case _ =>
f(m.asInstanceOf[U])
handle[T, Envs[E] & S, Any](v).asInstanceOf[T < S]
}
end run

override def accepts[M2[_], E2 <: Effect[M2, E2]](other: Effect[M2, E2]) =
Expand Down
4 changes: 4 additions & 0 deletions kyo-tapir/src/main/scala/kyo/routes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ object Routes:
f: I => O < (Fibers & Envs[A] & Aborts[E])
): Unit < Routes =
add(e(endpoint))(f)

def collect(init: (Unit < Routes)*): Unit < Routes =
Seqs.collect(init).unit

end Routes

0 comments on commit e86330e

Please sign in to comment.