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

Add Validated.ensure #984

Merged
merged 1 commit into from May 9, 2016
Merged

Add Validated.ensure #984

merged 1 commit into from May 9, 2016

Conversation

markus1189
Copy link
Contributor

Adds the ensure method known from Xor to Validated:

scala> Validated.valid("").ensure(new IllegalArgumentException("Must not be empty"))(_.nonEmpty)
res0: Validated[IllegalArgumentException,String] = Invalid(java.lang.IllegalArgumentException: Must not be empty)

@codecov-io
Copy link

Current coverage is 90.87%

Merging #984 into master will not affect coverage as of 869f4ce

@@            master    #984   diff @@
======================================
  Files          181     181       
  Stmts         2160    2160       
  Branches        42      43     +1
  Methods          0       0       
======================================
  Hit           1963    1963       
  Partial          0       0       
  Missed         197     197       

Review entire Coverage Diff as of 869f4ce

Powered by Codecov. Updated on successful CI builds.


test("ensure should fail if predicate not satisfied") {
forAll { (x: Validated[String, Int], s: String, p: Int => Boolean) =>
if (x.isValid && !p(x getOrElse 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively I think this could be if (x.exists(i => !(p(i)))). What's here is totally fine for a test though.

@ceedubs
Copy link
Contributor

ceedubs commented Apr 16, 2016

👍 thanks @markus1189!

@markus1189
Copy link
Contributor Author

I like your suggestion using exists better ;)

@stew
Copy link
Contributor

stew commented May 9, 2016

👍

@stew stew merged commit 19d0de0 into typelevel:master May 9, 2016
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.

None yet

4 participants