From 71fcdc07f0867476c2e8738418ba0e7d0d229a86 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Sat, 7 Nov 2015 10:19:57 -0500 Subject: [PATCH 1/2] Remove Validated.filter 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 #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`. --- core/src/main/scala/cats/data/Validated.scala | 9 --------- 1 file changed, 9 deletions(-) diff --git a/core/src/main/scala/cats/data/Validated.scala b/core/src/main/scala/cats/data/Validated.scala index a7d998f35f..90b75b613c 100644 --- a/core/src/main/scala/cats/data/Validated.scala +++ b/core/src/main/scala/cats/data/Validated.scala @@ -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. */ From c0deecf2f8d453d37abd7e9e57c47ce6350a8aa5 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Sat, 7 Nov 2015 10:28:19 -0500 Subject: [PATCH 2/2] Remove Validated.filter tests --- tests/src/test/scala/cats/tests/ValidatedTests.scala | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/src/test/scala/cats/tests/ValidatedTests.scala b/tests/src/test/scala/cats/tests/ValidatedTests.scala index 1e3383201e..1456d93ffd 100644 --- a/tests/src/test/scala/cats/tests/ValidatedTests.scala +++ b/tests/src/test/scala/cats/tests/ValidatedTests.scala @@ -42,14 +42,6 @@ class ValidatedTests extends CatsSuite { } } - test("filter makes non-matching entries invalid") { - Valid(1).filter[String](_ % 2 == 0).isInvalid should ===(true) - } - - test("filter leaves matching entries valid") { - Valid(2).filter[String](_ % 2 == 0).isValid should ===(true) - } - test("ValidatedNel") { forAll { (e: String) => val manual = Validated.invalid[NonEmptyList[String], Int](NonEmptyList(e))