From 73ed7f7b7af7e9102190f8d450858643c5bf53e6 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Sat, 7 Nov 2015 10:31:21 -0500 Subject: [PATCH] Remove EE >: E constraint from Validated.orElse This is the same as #575 but for Validated instead of Xor. --- core/src/main/scala/cats/data/Validated.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/data/Validated.scala b/core/src/main/scala/cats/data/Validated.scala index a7d998f35f..1f536a58c6 100644 --- a/core/src/main/scala/cats/data/Validated.scala +++ b/core/src/main/scala/cats/data/Validated.scala @@ -50,8 +50,11 @@ sealed abstract class Validated[+E, +A] extends Product with Serializable { /** * Return this if it is Valid, or else fall back to the given default. */ - def orElse[EE >: E, AA >: A](default: => Validated[EE,AA]): Validated[EE,AA] = - fold(_ => default, _ => this) + def orElse[EE, AA >: A](default: => Validated[EE,AA]): Validated[EE,AA] = + this match { + case v @ Valid(_) => v + case Invalid(_) => default + } /** * Converts the value to an Either[E,A]