Skip to content

Commit

Permalink
Remove Validated.filter
Browse files Browse the repository at this point in the history
I think this was leftover from copy/paste from `Xor`. It mentions that
it's useful when using `Validated` in for-comprehensions, but you can't
actually use `Validated` in for-comprehensions since it doesn't have a
`flatMap` method :).

Also, `Xor` no longer has a `filter` method. It was removed in typelevel#276
since using the monoid zero when the predicate doesn't match is rather
arbitrary and can lead to surprises. I think we should follow that
precedent for `Validated`.
  • Loading branch information
ceedubs committed Nov 7, 2015
1 parent e8435bd commit 71fcdc0
Showing 1 changed file with 0 additions and 9 deletions.
9 changes: 0 additions & 9 deletions core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ sealed abstract class Validated[+E, +A] extends Product with Serializable {
*/
def forall(f: A => Boolean): Boolean = fold(_ => true, f)

/**
* If the value is Valid but the predicate fails, return an empty
* Invalid value, otherwise leaves the value unchanged. This method
* is mostly useful for allowing validated values to be used in a
* for comprehension with pattern matching.
*/
def filter[EE >: E](pred: A => Boolean)(implicit M: Monoid[EE]): Validated[EE,A] =
fold(Invalid.apply, a => if(pred(a)) this else Invalid(M.empty))

/**
* Return this if it is Valid, or else fall back to the given default.
*/
Expand Down

0 comments on commit 71fcdc0

Please sign in to comment.