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

Remove Thunk.asFunction0 utility #3788

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,10 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
ProblemFilters.exclude[IncompatibleResultTypeProblem](
"cats.effect.unsafe.TimerSkipList.insert"),
ProblemFilters.exclude[IncompatibleResultTypeProblem](
"cats.effect.unsafe.WorkerThread.sleep")
"cats.effect.unsafe.WorkerThread.sleep"),
// #3787, internal utility that was no longer needed
ProblemFilters.exclude[MissingClassProblem]("cats.effect.Thunk"),
ProblemFilters.exclude[MissingClassProblem]("cats.effect.Thunk$")
) ++ {
if (tlIsScala3.value) {
// Scala 3 specific exclusions
Expand Down
8 changes: 4 additions & 4 deletions core/jvm/src/main/scala/cats/effect/IOCompanionPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ private[effect] abstract class IOCompanionPlatform { this: IO.type =>
* Implements [[cats.effect.kernel.Sync.blocking]].
*/
def blocking[A](thunk: => A): IO[A] = {
val fn = Thunk.asFunction0(thunk)
val fn = () => thunk
Blocking(TypeBlocking, fn, Tracing.calculateTracingEvent(fn.getClass))
}

// this cannot be marked private[effect] because of static forwarders in Java
@deprecated("use interruptible / interruptibleMany instead", "3.3.0")
def interruptible[A](many: Boolean, thunk: => A): IO[A] = {
val fn = Thunk.asFunction0(thunk)
val fn = () => thunk
Blocking(
if (many) TypeInterruptibleMany else TypeInterruptibleOnce,
fn,
Expand All @@ -80,7 +80,7 @@ private[effect] abstract class IOCompanionPlatform { this: IO.type =>
* Implements [[cats.effect.kernel.Sync.interruptible[A](thunk:=>A):*]]
*/
def interruptible[A](thunk: => A): IO[A] = {
val fn = Thunk.asFunction0(thunk)
val fn = () => thunk
Blocking(TypeInterruptibleOnce, fn, Tracing.calculateTracingEvent(fn.getClass))
}

Expand All @@ -104,7 +104,7 @@ private[effect] abstract class IOCompanionPlatform { this: IO.type =>
* Implements [[cats.effect.kernel.Sync!.interruptibleMany]]
*/
def interruptibleMany[A](thunk: => A): IO[A] = {
val fn = Thunk.asFunction0(thunk)
val fn = () => thunk
Blocking(TypeInterruptibleMany, fn, Tracing.calculateTracingEvent(fn.getClass))
}

Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits {
* Any exceptions thrown by the effect will be caught and sequenced into the `IO`.
*/
def delay[A](thunk: => A): IO[A] = {
val fn = Thunk.asFunction0(thunk)
val fn = () => thunk
Delay(fn, Tracing.calculateTracingEvent(fn))
}

Expand Down
29 changes: 0 additions & 29 deletions core/shared/src/main/scala/cats/effect/Thunk.scala

This file was deleted.

4 changes: 2 additions & 2 deletions tests/shared/src/test/scala/cats/effect/ThunkSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package cats.effect

class ThunkSpec extends BaseSpec {

"Thunk.asFunction0" should {
"IO.delay" should {
"return the same function" in {
var i = 0
val f = () => i += 1
Thunk.asFunction0(f()) eq f
IO.delay(f()).asInstanceOf[IO.Delay[Unit]].thunk eq f
}
}

Expand Down