Skip to content

Commit

Permalink
fixed implementation leading to timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
iusildra committed May 22, 2023
1 parent 81774d1 commit 61dbc60
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ sealed abstract class Validation[+A] {
def isInvalid: Boolean = !isValid
def isEmpty: Boolean = isInvalid

def filter(p: A => Boolean, fatal: Boolean = false): Validation[A] =
if (isValid && p(get)) this
else if (fatal) Unrecoverable(s"Predicate does not hold for $get")
else Recoverable(s"Predicate does not hold for $get")
def filter(p: A => Boolean, fatal: Boolean = false): Validation[A]
def filterNot(p: A => Boolean, fatal: Boolean = false): Validation[A] = filter(!p(_), fatal)

def map[B](f: A => B): Validation[B]
Expand Down Expand Up @@ -43,6 +40,11 @@ final case class Valid[+A](value: A) extends Validation[A]() {
override def getOrElse[B >: A](f: => B): B = value
override def orElse[B >: A](f: => Validation[B]): Validation[B] = this

override def filter(p: A => Boolean, fatal: Boolean): Validation[A] =
if (p(value)) this
else if (fatal) Unrecoverable(s"Predicate does not hold for $value")
else Recoverable(s"Predicate does not hold for $value")

override def recoverWith[B >: A](f: => Validation[B]): Validation[B] = this

override def toOption: Option[A] = Some(value)
Expand All @@ -56,6 +58,8 @@ sealed abstract class Invalid(val exception: Exception) extends Validation[Nothi
override def get = throw exception
override def getOrElse[B >: Nothing](f: => B): B = f

override def filter(p: Nothing => Boolean, fatal: Boolean): Validation[Nothing] = this

override def recoverWith[B >: Nothing](f: => Validation[B]): Validation[B] = f

override def toOption: Option[Nothing] = None
Expand Down

0 comments on commit 61dbc60

Please sign in to comment.