Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
18 changes: 12 additions & 6 deletions core/shared/src/main/scala/zio/Schedule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ object Schedule {
final def identity[A]: Schedule[A, A] =
ZSchedule.identity

/**
* See [[ZSchedule.logInput]]
*/
final def logInput[A](f: A => UIO[Unit]): Schedule[A, A] =
ZSchedule.logInput(f)

/**
* See [[ZSchedule.recurs]]
*/
Expand All @@ -145,6 +139,18 @@ object Schedule {
final def succeedLazy[A](a: => A): Schedule[Any, A] =
succeed(a)

/**
* See [[ZSchedule.tapInput]]
*/
final def tapInput[A](f: A => UIO[Unit]): Schedule[A, A] =
ZSchedule.tapInput(f)

/**
* See [[ZSchedule.tapOutput]]
*/
final def tapOutput[A](f: A => UIO[Unit]): Schedule[A, A] =
ZSchedule.tapOutput(f)

/**
* See [[ZSchedule.unfold]]
*/
Expand Down
45 changes: 26 additions & 19 deletions core/shared/src/main/scala/zio/ZSchedule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -436,18 +436,6 @@ trait ZSchedule[-R, -A, +B] extends Serializable { self =>
*/
final def left[C]: ZSchedule[R, Either[A, C], Either[B, C]] = self +++ ZSchedule.identity[C]

/**
* Sends every input value to the specified sink.
*/
final def logInput[R1 <: R, A1 <: A](f: A1 => ZIO[R1, Nothing, Unit]): ZSchedule[R1, A1, B] =
updated(update => (a, s) => f(a) *> update(a, s))

/**
* Sends every output value to the specified sink.
*/
final def logOutput[R1 <: R](f: B => ZIO[R1, Nothing, Unit]): ZSchedule[R1, A, B] =
updated(update => (a, s) => update(a, s).flatMap(s1 => f(self.extract(a, s1)).as(s1)))

/**
* Returns a new schedule that maps over the output of this one.
*/
Expand Down Expand Up @@ -564,6 +552,18 @@ trait ZSchedule[-R, -A, +B] extends Serializable { self =>
*/
final def second[C]: ZSchedule[R, (C, A), (C, B)] = ZSchedule.identity[C] *** self

/**
* Sends every input value to the specified sink.
*/
final def tapInput[R1 <: R, A1 <: A](f: A1 => ZIO[R1, Nothing, Unit]): ZSchedule[R1, A1, B] =
updated(update => (a, s) => f(a) *> update(a, s))

/**
* Sends every output value to the specified sink.
*/
final def tapOutput[R1 <: R](f: B => ZIO[R1, Nothing, Unit]): ZSchedule[R1, A, B] =
updated(update => (a, s) => update(a, s).flatMap(s1 => f(self.extract(a, s1)).as(s1)))

/**
* Returns a new schedule with the update function transformed by the
* specified update transformer.
Expand Down Expand Up @@ -864,13 +864,6 @@ object ZSchedule {
final def linear(base: Duration): ZSchedule[Clock, Any, Duration] =
delayed(forever.map(i => base * (i + 1).doubleValue()))

/**
* A schedule that recurs forever, dumping input values to the specified
* sink, and returning those same values unmodified.
*/
final def logInput[R, A](f: A => ZIO[R, Nothing, Unit]): ZSchedule[R, A, A] =
identity[A].logInput(f)

/**
* A schedule that waits forever when updating or initializing.
*/
Expand Down Expand Up @@ -952,6 +945,20 @@ object ZSchedule {
final def succeedLazy[A](a: => A): Schedule[Any, A] =
succeed(a)

/**
* A schedule that recurs forever, dumping input values to the specified
* sink, and returning those same values unmodified.
*/
final def tapInput[R, A](f: A => ZIO[R, Nothing, Unit]): ZSchedule[R, A, A] =
identity[A].tapInput(f)

/**
* A schedule that recurs forever, dumping output values to the specified
* sink, and returning those same values unmodified.
*/
final def tapOutput[R, A](f: A => ZIO[R, Nothing, Unit]): ZSchedule[R, A, A] =
identity[A].tapOutput(f)

/**
* A schedule that always recurs without delay, and computes the output
* through recured application of a function to a base value.
Expand Down