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
8 changes: 8 additions & 0 deletions core-tests/shared/src/test/scala/zio/ZIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,14 @@ object ZIOSpec extends ZIOBaseSpec {
assertM(task.run)(fails(isSome(equalTo(ex))))
} @@ zioTag(errors)
),
suite("negate")(
testM("on true returns false") {
assertM(ZIO.succeed(true).negate)(equalTo(false))
},
testM("on false returns true") {
assertM(ZIO.succeed(false).negate)(equalTo(true))
}
),
suite("once")(
testM("returns an effect that will only be executed once") {
for {
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/main/scala/zio/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,12 @@ object IO {
*/
val none: UIO[Option[Nothing]] = ZIO.none

/**
* @see See [[zio.ZIO.not]]
*/
def not[E](effect: IO[E, Boolean]): IO[E, Boolean] =
ZIO.not(effect)

/**
* @see See [[zio.ZIO.partition]]
*/
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/main/scala/zio/RIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,12 @@ object RIO {
*/
val none: UIO[Option[Nothing]] = ZIO.none

/**
* @see See [[zio.ZIO.not]]
*/
def not[R](effect: RIO[R, Boolean]): RIO[R, Boolean] =
ZIO.not(effect)

/**
* @see See [[zio.ZIO.partition]]
*/
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/main/scala/zio/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ object Task extends TaskPlatformSpecific {
*/
val none: Task[Option[Nothing]] = ZIO.none

/**
* @see See [[zio.ZIO.not]]
*/
def not(effect: Task[Boolean]): Task[Boolean] =
ZIO.not(effect)

/**
* @see See [[zio.ZIO.partition]]
*/
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/main/scala/zio/UIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ object UIO {
*/
val never: UIO[Nothing] = ZIO.never

/**
* @see See [[zio.ZIO.not]]
*/
def not(effect: UIO[Boolean]): UIO[Boolean] =
ZIO.not(effect)

/**
* @see See [[zio.ZIO.raceAll]]
*/
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/main/scala/zio/URIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ object URIO {
*/
val none: UIO[Option[Nothing]] = ZIO.none

/**
* @see See [[zio.ZIO.not]]
*/
def not[R](effect: URIO[R, Boolean]): URIO[R, Boolean] =
ZIO.not(effect)

/**
* @see [[zio.ZIO.provide]]
*/
Expand Down
12 changes: 12 additions & 0 deletions core/shared/src/main/scala/zio/ZIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,12 @@ sealed trait ZIO[-R, +E, +A] extends Serializable with ZIOPlatformSpecific[R, E,
final def merge[A1 >: A](implicit ev1: E <:< A1, ev2: CanFail[E]): URIO[R, A1] =
self.foldM(e => ZIO.succeedNow(ev1(e)), ZIO.succeedNow)

/**
* Returns a new effect where boolean value of this effect is negated.
*/
final def negate(implicit ev: A <:< Boolean): ZIO[R, E, Boolean] =
map(result => !result)

/**
* Requires the option produced by this value to be `None`.
*/
Expand Down Expand Up @@ -3291,6 +3297,12 @@ object ZIO extends ZIOCompanionPlatformSpecific {
if (cont(initial)) body(initial) *> loop_(inc(initial))(cont, inc)(body)
else ZIO.unit

/**
* Returns a new effect where boolean value of this effect is negated.
*/
def not[R, E](effect: ZIO[R, E, Boolean]): ZIO[R, E, Boolean] =
effect.negate

/**
* Sequentially zips the specified effects. Specialized version of mapN.
*/
Expand Down