Skip to content

Add Validated.ensure#984

Merged
stew merged 1 commit into
typelevel:masterfrom
markus1189:validated-ensure
May 9, 2016
Merged

Add Validated.ensure#984
stew merged 1 commit into
typelevel:masterfrom
markus1189:validated-ensure

Conversation

@markus1189
Copy link
Copy Markdown
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
Copy Markdown

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

ceedubs commented Apr 16, 2016

👍 thanks @markus1189!

@markus1189
Copy link
Copy Markdown
Contributor Author

I like your suggestion using exists better ;)

@stew
Copy link
Copy Markdown
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.

4 participants