From 26a044b964f5e86469eb95908be68408bd866bcb Mon Sep 17 00:00:00 2001 From: "Marius B. Kotsbak" Date: Tue, 14 Jun 2016 14:20:32 +0200 Subject: [PATCH] Add valueOr to Validated, analog to Xor.valueOr --- core/src/main/scala/cats/data/Validated.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/scala/cats/data/Validated.scala b/core/src/main/scala/cats/data/Validated.scala index 0d52616c4ab..f1ac3f6645d 100644 --- a/core/src/main/scala/cats/data/Validated.scala +++ b/core/src/main/scala/cats/data/Validated.scala @@ -27,6 +27,11 @@ sealed abstract class Validated[+E, +A] extends Product with Serializable { */ def getOrElse[B >: A](default: => B): B = fold(_ => default, identity) + /** + * Return the Valid value, or the result of f if Invalid + */ + def valueOr[B >: A](f: E => B): B = fold(f, identity) + /** * Is this Valid and matching the given predicate */