Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@phderome
Copy link
Contributor

@phderome phderome commented May 9, 2021

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 .unit

Solution: now leverages partitionPar as per @adamgfraser comment to avoid superfluous data construction of BuildFrom

Copy link
Contributor

@adamgfraser adamgfraser left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def fail[A](a: A): IO[A, A] = IO.fail(a)
def fail[A](a: A): IO[A, Nothing] = IO.fail(a)

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

@phderome phderome May 9, 2021

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@phderome
Copy link
Contributor Author

phderome commented May 9, 2021

Looks good! Do you want to also add versions for the other validate variants as well?

Phil says: I may as well, yes, I didn't think of it.

phderome added 3 commits May 9, 2021 12:43
…tePar-discard

# Conflicts:
#	core-tests/shared/src/test/scala/zio/ZIOSpec.scala
@phderome phderome changed the title add support for validatePar_ add support for validatePar_ and validate_ May 9, 2021
@phderome
Copy link
Contributor Author

phderome commented May 9, 2021

all checks passed.

@phderome
Copy link
Contributor Author

phderome commented May 10, 2021

Should I squash commits on this PR?
Coding style says the underscore usage in this PR is discouraged, thoughts @adamgfraser?
Consider methods ending with _ having more meaningful names;

Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

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

Thank you! 🙏

@adamgfraser adamgfraser merged commit 7668f6b into zio:master May 10, 2021
@phderome phderome deleted the validatePar-discard branch May 10, 2021 10:12
@phderome
Copy link
Contributor Author

thank you for the review.

@adamgfraser
Copy link
Contributor

Definitely! By the way I realized I didn't answer your question about the _ naming. I think we would like to move away from the _ naming for ZIO 2.0 but I can't say we have a better alternative at this point and we definitely have comparable methods with similar naming in ZIO 1.0 such as foreachPar_ and collectAllPar_ so I think the naming is correct for now, though could possibly be improved in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants