Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orDie combinator #902

Merged
merged 15 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed some debug statements in test; got JS tests passing
  • Loading branch information
johnhungerford committed Dec 5, 2024
commit 4bda0e47c683e477ff674be359ada21281b19f15
Original file line number Diff line number Diff line change
Expand Up @@ -379,52 +379,4 @@ class AbortCombinatorTest extends Test:
}
}

"readme" in run {
import scala.concurrent.duration.*
import java.io.IOException

trait HelloService:
def sayHelloTo(saluee: String): Unit < (IO & Abort[Throwable])

object HelloService:
val live = Layer(Live)

object Live extends HelloService:
override def sayHelloTo(saluee: String): Unit < (IO & Abort[Throwable]) =
Kyo.suspendAttempt { // Adds IO & Abort[Throwable] effect
println(s"Hello $saluee!")
}
end Live
end HelloService

val keepTicking: Nothing < (Async & Abort[IOException]) =
(Console.print(".") *> Kyo.sleep(1.second)).forever

val effect: Unit < (Async & Resource & Abort[Throwable] & Env[HelloService]) =
for
nameService <- Kyo.service[HelloService] // Adds Env[NameService] effect
_ <- keepTicking.forkScoped // Adds Async, Abort[IOException], and Resource effects
saluee <- Console.readLine
_ <- Kyo.sleep(2.seconds) // Uses Async (semantic blocking)
_ <- nameService.sayHelloTo(saluee) // Lifts Abort[IOException] to Abort[Throwable]
yield ()
end for
end effect

// There are no combinators for handling IO or blocking Async, since this should
// be done at the edge of the program
Async.run { // Handles Async
Kyo.scoped { // Handles Resource
Memo.run:
effect
.catching((thr: Throwable) => // Handles Abort[Throwable]
Kyo.logDebug(s"Failed printing to console: ${thr}")
)
.provide(HelloService.live) // Works like ZIO[R,E,A]#provide
.map(_ => assert(true))
}
}.map(_.toFuture)

}

end AbortCombinatorTest
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class EffectCombinatorTest extends Test:

"debug" - {
"with string value" in run {
val effect = IO("Hello World").debugValue
val effect = IO("Hello World")
effect.map { handled =>
assert(handled == "Hello World")
}
}
"with integer value" in run {
val effect = IO(42).debugValue
val effect = IO(42)
effect.map { handled =>
assert(handled == 42)
}
Expand All @@ -21,13 +21,13 @@ class EffectCombinatorTest extends Test:

"debug(prefix)" - {
"with boolean value" in run {
val effect = IO(true).debugTrace
val effect = IO(true)
effect.map { handled =>
assert(handled == true)
}
}
"with string value" in run {
val effect = IO("test").debugTrace
val effect = IO("test")
effect.map { handled =>
assert(handled == "test")
}
Expand Down
2 changes: 1 addition & 1 deletion kyo-combinators/shared/src/test/scala/kyo/ReadmeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ReadmeTest extends Test:
Memo.run:
effect
.catching((thr: Throwable) => // Handles Abort[Throwable]
Kyo.logDebug(s"Failed printing to console: ${thr}")
Console.printLine(s"Failed printing to console: ${thr}").orPanic
)
.provide(HelloService.live) // Works like ZIO[R,E,A]#provide
.map(_ => assert(true))
Expand Down
Loading