-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1245 from geny200/feature/lift-effects
Add transformers support for effects
- Loading branch information
Showing
19 changed files
with
259 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
modules/kernel/src/main/scala-2/tofu/internal/instances/SleepInstance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package tofu.internal.instances | ||
|
||
import tofu.higherKind | ||
import tofu.higherKind.RepresentableK | ||
import tofu.internal.carriers.{SleepCE2Carrier, SleepCE3Carrier} | ||
import tofu.time.Sleep | ||
import tofu.internal.carriers.SleepCE3Carrier | ||
import tofu.internal.carriers.SleepCE2Carrier | ||
|
||
private[tofu] trait SleepInstance extends SleepInstance0 { | ||
implicit def ce3Interop[F[_]](implicit sleep: SleepCE3Carrier[F]): Sleep[F] = sleep | ||
} | ||
|
||
private[tofu] trait SleepInstance0 { | ||
implicit def ce2Interop[F[_]](implicit sleep: SleepCE2Carrier[F]): Sleep[F] = sleep | ||
|
||
implicit val sleepRepresentableK: RepresentableK[Sleep] = higherKind.derived.genRepresentableK[Sleep] | ||
} |
9 changes: 9 additions & 0 deletions
9
modules/kernel/src/main/scala-2/tofu/internal/instances/TimeZoneInstance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tofu.internal.instances | ||
|
||
import tofu.higherKind | ||
import tofu.higherKind.RepresentableK | ||
import tofu.time.TimeZone | ||
|
||
private[tofu] trait TimeZoneInstance { | ||
implicit val timeZoneRepresentableK: RepresentableK[TimeZone] = higherKind.derived.genRepresentableK[TimeZone] | ||
} |
11 changes: 11 additions & 0 deletions
11
modules/kernel/src/main/scala-3/tofu/internal/instances/ClockInstance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
package tofu.internal | ||
package instances | ||
|
||
import cats.~> | ||
import tofu.higherKind.{RepK, RepresentableK} | ||
import tofu.internal.carriers.ClockCE3Carrier | ||
import tofu.internal.carriers.ClockCE2Carrier | ||
import tofu.time.Clock | ||
|
||
import java.util.concurrent.TimeUnit | ||
import scala.compiletime.summonFrom | ||
|
||
private[tofu] trait ClockInstance: | ||
inline given [F[_]]: Clock[F] = summonFrom { | ||
case carrier: ClockCE3Carrier[F] => carrier | ||
case carrier: ClockCE2Carrier[F] => carrier | ||
} | ||
|
||
// TODO: use higherKind.derived macro when it is ready for scala 3 | ||
given clockRepresentableK: RepresentableK[Clock] = new RepresentableK[Clock] { | ||
def tabulate[F[_]](hom: RepK[Clock, _] ~> F): Clock[F] = new Clock[F] { | ||
def realTime(unit: TimeUnit): F[Long] = hom(RepK[Clock](_.realTime(unit))) | ||
def nanos: F[Long] = hom(RepK[Clock](_.nanos)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
modules/kernel/src/main/scala-3/tofu/internal/instances/SleepInstance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
package tofu.internal | ||
package instances | ||
|
||
import cats.~> | ||
import tofu.higherKind.{RepK, RepresentableK} | ||
import tofu.internal.carriers.{SleepCE2Carrier, SleepCE3Carrier} | ||
import tofu.time.Sleep | ||
|
||
import scala.compiletime.summonFrom | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
private[tofu] trait SleepInstance: | ||
inline given [F[_]]: Sleep[F] = | ||
summonFrom { | ||
case carrier: SleepCE3Carrier[F] => carrier | ||
case carrier: SleepCE2Carrier[F] => carrier | ||
} | ||
|
||
// TODO: use higherKind.derived macro when it is ready for scala 3 | ||
given sleepRepresentableK: RepresentableK[Sleep] = new RepresentableK[Sleep] { | ||
def tabulate[F[_]](hom: RepK[Sleep, _] ~> F): Sleep[F] = new Sleep[F] { | ||
def sleep(duration: FiniteDuration): F[Unit] = hom(RepK[Sleep](_.sleep(duration))) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
modules/kernel/src/main/scala-3/tofu/internal/instances/TimeZoneInstance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package tofu.internal.instances | ||
|
||
import cats.~> | ||
import tofu.higherKind.{RepK, RepresentableK} | ||
import tofu.time.TimeZone | ||
|
||
import java.time.{ZoneId, ZoneOffset} | ||
|
||
trait TimeZoneInstance: | ||
// TODO: use higherKind.derived macro when it is ready for scala 3 | ||
given timeZoneRepresentableK: RepresentableK[TimeZone] = new RepresentableK[TimeZone] { | ||
def tabulate[F[_]](hom: RepK[TimeZone, _] ~> F): TimeZone[F] = new TimeZone[F] { | ||
override def system: F[ZoneId] = hom(RepK[TimeZone](_.system)) | ||
override def available: F[Set[String]] = hom(RepK[TimeZone](_.available)) | ||
override def of(zoneId: String): F[ZoneId] = hom(RepK[TimeZone](_.of(zoneId))) | ||
override def ofOffset(prefix: String, offset: ZoneOffset): F[ZoneId] = | ||
hom(RepK[TimeZone](_.ofOffset(prefix, offset))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
package tofu | ||
|
||
import cats.data.* | ||
import cats.{Applicative, FlatMap, Functor, Monoid} | ||
import tofu.internal.EffectComp | ||
import tofu.internal.instances.DelayInstance | ||
import tofu.syntax.liftKernel.CatsTaglessLiftSyntax | ||
|
||
trait Delay[F[_]] { | ||
def delay[A](a: => A): F[A] | ||
} | ||
|
||
object Delay extends DelayInstance with EffectComp[Delay] { | ||
object Delay extends EffectComp[Delay] with DelayInstance { | ||
type Safe[F[_, _]] = Delay[F[Nothing, _]] | ||
type Catch[F[_, _]] = Delay[F[Throwable, _]] | ||
|
||
implicit def delayForKleisli[F[_]: Delay, R]: Delay[Kleisli[F, R, _]] = Delay[F].lift | ||
implicit def delayForWriterT[F[_]: Applicative: Delay, R: Monoid]: Delay[WriterT[F, R, _]] = Delay[F].lift | ||
implicit def delayForOptionT[F[_]: Functor: Delay]: Delay[OptionT[F, _]] = Delay[F].lift | ||
implicit def delayForEitherT[F[_]: Functor: Delay, E]: Delay[EitherT[F, E, _]] = Delay[F].lift | ||
implicit def delayForStateT[F[_]: Applicative: Delay, S]: Delay[StateT[F, S, _]] = Delay[F].lift | ||
implicit def delayForIorT[F[_]: Applicative: Delay, L]: Delay[IorT[F, L, _]] = Delay[F].lift | ||
implicit def delayForContT[F[_]: FlatMap: Delay, R]: Delay[ContT[F, R, _]] = Delay[F].lift | ||
implicit def delayForRWST[F[_]: Applicative: Delay, R, L: Monoid, S]: Delay[RWST[F, R, L, S, _]] = Delay[F].lift | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.