This repository has been archived by the owner on Mar 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
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 #63 from mschuwalow/feature/zschedule-syntax
add Schedule syntax
- Loading branch information
Showing
7 changed files
with
75 additions
and
26 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
19 changes: 19 additions & 0 deletions
19
core/shared/src/main/scala/zio/macros/delegate/ZIOSyntax.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 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_) | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
core/shared/src/main/scala/zio/macros/delegate/ZManagedSyntax.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 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) | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
core/shared/src/main/scala/zio/macros/delegate/ZScheduleSyntax.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,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) })) | ||
} | ||
|
||
} |
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
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 |