-
Couldn't load subscription status.
- Fork 1.4k
add support for validatePar_ and validate_ #5054
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Do you want to also add versions for the other validate variants as well?
| suite("validatePar_")( | ||
| testM("returns all errors if never valid") { | ||
| val in = List.fill(10)(0) | ||
| def fail[A](a: A): IO[A, A] = IO.fail(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def fail[A](a: A): IO[A, A] = IO.fail(a) | |
| def fail[A](a: A): IO[A, Nothing] = IO.fail(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed.
| def validatePar_[R, E, A, Collection[+Element] <: Iterable[Element]](in: Collection[A])( | ||
| f: A => ZIO[R, E, Any] | ||
| )(implicit bf: BuildFrom[Collection[A], Any, Collection[Any]], ev: CanFail[E]): ZIO[R, ::[E], Unit] = | ||
| validatePar(in)(f).unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the success case here there is no need to build the collection if we are going to immediately discard it. I think this will also let us to remove the BuildFrom constraint and accept any Iterable instead of Collection[+Element] <: Iterable[Element], which will allow this operator to work with some other collection types like arrays and sets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, addressed in later commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement on the signature! We can still avoid unnecessarily creating the collection by implementing in terms of partitionPar directly and returning the unit value if there are no errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, addressed in latest commit.
Co-authored-by: Adam Fraser <[email protected]>
Phil says: I may as well, yes, I didn't think of it. |
…tePar-discard # Conflicts: # core-tests/shared/src/test/scala/zio/ZIOSpec.scala
|
all checks passed. |
|
Should I squash commits on this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 🙏
|
thank you for the review. |
|
Definitely! By the way I realized I didn't answer your question about the |
A possible purpose or use case is to execute jobs that are side-effecting (returning
Unit) whose overall success value is not interesting but knowing about all failures remains useful. Proposed solution: call.unitSolution: now leverages
partitionParas per @adamgfraser comment to avoid superfluous data construction ofBuildFrom