Skip to content

Commit

Permalink
Optimize ZPure#unit (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Apr 27, 2024
1 parent 25a1705 commit 1664a14
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/shared/src/main/scala/zio/prelude/fx/ZPure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -967,13 +967,15 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
/**
* Maps the value of this computation to unit.
*/
final def unit: ZPure[W, S1, S2, R, E, Unit] = as(())
final def unit: ZPure[W, S1, S2, R, E, Unit] =
self.flatMap(succeedUnitFn)

}

object ZPure {
private val succeedUnit: ZPure[Nothing, Any, Nothing, Any, Nothing, Unit] = Succeed(())
private val succeedNone: ZPure[Nothing, Any, Nothing, Any, Nothing, Option[Nothing]] = Succeed(None)
private val succeedUnitFn = (_: Any) => succeedUnit

/**
* Constructs a computation, catching any `Throwable` that is thrown.
Expand Down

0 comments on commit 1664a14

Please sign in to comment.