Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #63 from mschuwalow/feature/zschedule-syntax
Browse files Browse the repository at this point in the history
add Schedule syntax
  • Loading branch information
mschuwalow authored Dec 6, 2019
2 parents 82c8e22 + b55ceab commit 535b199
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import zio._
import zio.clock.Clock
import zio.blocking.Blocking
import zio.console.Console
import zio.macros.delegate.syntax._

object EnrichWithExample {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package zio.macros.delegate

import zio.ZEnv
import zio._
import zio.clock.Clock

object PatchExample {

val mapClock: (Clock.Service[Any] => Clock.Service[Any]) => ZEnv => ZEnv =
f => patch[ZEnv, Clock].apply(c => new Clock { val clock = f(c.clock) })

}
19 changes: 19 additions & 0 deletions core/shared/src/main/scala/zio/macros/delegate/ZIOSyntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package zio.macros.delegate

import zio._

trait ZIOSyntax {

implicit class ZIOOps[R, E, A](zio: ZIO[R, E, A]) {

def @@[B](enrichWith: EnrichWith[B])(implicit ev: A Mix B): ZIO[R, E, A with B] =
enrichWith.enrichZIO[R, E, A](zio)

def @@[B](enrichWithM: EnrichWithM[A, E, B])(implicit ev: A Mix B): ZIO[R, E, A with B] =
enrichWithM.enrichZIO[R, E, A](zio)

def @@[B](enrichWithManaged: EnrichWithManaged[A, E, B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWithManaged.enrichZManaged[R, E, A](zio.toManaged_)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package zio.macros.delegate

import zio._

trait ZManagedSyntax {

implicit class ZManagedOps[R, E, A](zManaged: ZManaged[R, E, A]) {

def @@[B](enrichWith: EnrichWith[B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWith.enrichZManaged[R, E, A](zManaged)

def @@[B](enrichWithM: EnrichWithM[A, E, B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWithM.enrichZManaged[R, E, A](zManaged)

def @@[B](enrichWithManaged: EnrichWithManaged[A, E, B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWithManaged.enrichZManaged[R, E, A](zManaged)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package zio.macros.delegate

import zio._
import zio.clock.Clock
import zio.random.Random
import zio.duration.Duration

trait ZScheduleSyntax {

implicit class ZScheduleSyntax[R, A, B](zSchedule: ZSchedule[R, A, B]) {

def delayed$[R1 <: R with Clock](f: Duration => Duration)(implicit ev: R Mix Clock): ZSchedule[R1, A, B] =
zSchedule.delayedEnv(f)(g => patch[R, Clock].apply(c => new Clock { val clock = g(c.clock) }))

def delayedM$[R1 <: R with Clock](
f: Duration => ZIO[R1, Nothing, Duration]
)(implicit ev: R Mix Clock): ZSchedule[R1, A, B] =
zSchedule.delayedMEnv(f)(g => patch[R, Clock].apply(c => new Clock { val clock = g(c.clock) }))

def jittered$[R1 <: R with Clock with Random](min: Double = 0.0, max: Double = 1.0)(
implicit ev: R Mix Clock
): ZSchedule[R1, A, B] =
zSchedule.jitteredEnv(min, max)(f => patch[R, Clock].apply(c => new Clock { val clock = f(c.clock) }))

def modifyDelay$[R1 <: R with Clock](
f: (B, Duration) => ZIO[R1, Nothing, Duration]
)(implicit ev: R Mix Clock): ZSchedule[R1, A, B] =
zSchedule.modifyDelayEnv(f)(g => patch[R, Clock].apply(c => new Clock { val clock = g(c.clock) }))
}

}
25 changes: 0 additions & 25 deletions core/shared/src/main/scala/zio/macros/delegate/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package zio.macros

import zio._

package object delegate {

/**
Expand All @@ -43,27 +41,4 @@ package object delegate {
*/
def enrichWithManaged[A]: EnrichWithManaged.PartiallyApplied[A] = new EnrichWithManaged.PartiallyApplied

implicit class ZIOSyntax[R, E, A](zio: ZIO[R, E, A]) {

def @@[B](enrichWith: EnrichWith[B])(implicit ev: A Mix B): ZIO[R, E, A with B] =
enrichWith.enrichZIO[R, E, A](zio)

def @@[B](enrichWithM: EnrichWithM[A, E, B])(implicit ev: A Mix B): ZIO[R, E, A with B] =
enrichWithM.enrichZIO[R, E, A](zio)

def @@[B](enrichWithManaged: EnrichWithManaged[A, E, B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWithManaged.enrichZManaged[R, E, A](zio.toManaged_)
}

implicit class ZManagedSyntax[R, E, A](zManaged: ZManaged[R, E, A]) {

def @@[B](enrichWith: EnrichWith[B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWith.enrichZManaged[R, E, A](zManaged)

def @@[B](enrichWithM: EnrichWithM[A, E, B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWithM.enrichZManaged[R, E, A](zManaged)

def @@[B](enrichWithManaged: EnrichWithManaged[A, E, B])(implicit ev: A Mix B): ZManaged[R, E, A with B] =
enrichWithManaged.enrichZManaged[R, E, A](zManaged)
}
}
3 changes: 3 additions & 0 deletions core/shared/src/main/scala/zio/macros/delegate/syntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package zio.macros.delegate

object syntax extends ZIOSyntax with ZManagedSyntax with ZScheduleSyntax

0 comments on commit 535b199

Please sign in to comment.