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
11 changes: 9 additions & 2 deletions core/shared/src/main/scala/zio/ZIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ sealed trait ZIO[-R, +E, +A] extends Serializable { self =>
/**
* Maps the success value of this effect to the specified constant value.
*/
final def as[B](b: B): ZIO[R, E, B] = self.flatMap(new ZIO.ConstFn(() => b))
final def as[B](b: => B): ZIO[R, E, B] = self.flatMap(new ZIO.ConstZIOFn(() => b))

/**
* Maps the error value of this effect to the specified constant value.
Expand Down Expand Up @@ -2649,13 +2649,20 @@ object ZIO extends ZIOFunctions {
new ZIO.Succeed(underlying(a))
}

final class ConstFn[R, E, A, B](override val underlying: () => B) extends ZIOFn1[A, ZIO[R, E, B]] {
final class ConstZIOFn[R, E, A, B](override val underlying: () => B) extends ZIOFn1[A, ZIO[R, E, B]] {
def apply(a: A): ZIO[R, E, B] = {
val _ = a
new ZIO.Succeed(underlying())
}
}

final class ConstFn[A, B](override val underlying: () => B) extends ZIOFn1[A, B] {
def apply(a: A): B = {
val _ = a
underlying()
}
}

final class BracketReleaseFn[R, E, A, B](override val underlying: A => ZIO[R, Nothing, _])
extends ZIOFn2[A, Exit[E, B], ZIO[R, Nothing, _]] {
override def apply(a: A, exit: Exit[E, B]): ZIO[R, Nothing, _] = {
Expand Down
2 changes: 1 addition & 1 deletion streams/shared/src/main/scala/zio/stream/ZStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class ZStream[-R, +E, +A](val process: ZManaged[R, E, Pull[R, E, A]]) extends Se
/**
* Maps the success values of this stream to the specified constant value.
*/
final def as[B](b: B): ZStream[R, E, B] = map(_ => b)
final def as[B](b: => B): ZStream[R, E, B] = map(new ZIO.ConstFn(() => b))

/**
* Returns a stream whose failure and success channels have been mapped by
Expand Down