Skip to content

Commit

Permalink
Merge pull request #3788 from armanbilge/topic/bye-thunk
Browse files Browse the repository at this point in the history
Remove `Thunk.asFunction0` utility
  • Loading branch information
armanbilge authored Aug 22, 2023
2 parents a77a2f1 + 88594c6 commit b9f5694
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
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

0 comments on commit b9f5694

Please sign in to comment.