Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZValidation: add get, getOrElse, getOrElseWith #802

Merged
merged 3 commits into from
Nov 13, 2021
Merged
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions core/shared/src/main/scala/zio/prelude/ZValidation.scala
Original file line number Diff line number Diff line change
@@ -245,6 +245,16 @@ sealed trait ZValidation[+W, +E, +A] { self =>
ZIO.succeedNow
)

/**
* Returns the value, because no error has occurred.
*/
final def value(implicit ev: E <:< Nothing): A = self.asInstanceOf[Success[W, A]].value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get and getOrElseWith? Can probably just fold with ev here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided not to use ev, because I have NonEmptyChunk[E] and although I could go out of my way to "prove" that is "absurd", it would probably be more hassle than it's worth it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


/**
* Returns the successful value or handles the errors that have accumulated.
*/
final def valueOr[A1 >: A](f: NonEmptyChunk[E] => A1): A1 = fold(f, identity)

/**
* A variant of `zipPar` that keeps only the left success value, but returns
* a failure with all errors if either this `ZValidation` or the specified