Skip to content

Commit

Permalink
Validated is rigid
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Dec 17, 2020
1 parent b56130d commit 9079e16
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ sealed abstract private[data] class ValidatedInstances extends ValidatedInstance

implicit def catsDataSelectiveErrorForValidated[E](implicit
E: Semigroup[E]
): Selective[Validated[E, *]] with ApplicativeError[Validated[E, *], E] =
): RigidSelective[Validated[E, *]] with ApplicativeError[Validated[E, *], E] =
new ValidatedSelective[E] with ApplicativeError[Validated[E, *], E] {
def handleErrorWith[A](fa: Validated[E, A])(f: E => Validated[E, A]): Validated[E, A] =
fa match {
Expand Down Expand Up @@ -1044,13 +1044,18 @@ sealed abstract private[data] class ValidatedInstances2 {
// scalastyle:off method.length
}

private[data] class ValidatedSelective[E: Semigroup] extends ValidatedApplicative[E] with Selective[Validated[E, *]] {
private[data] class ValidatedSelective[E: Semigroup]
extends ValidatedApplicative[E]
with RigidSelective[Validated[E, *]] {
override def select[A, B](fab: Validated[E, Either[A, B]])(ff: => Validated[E, A => B]): Validated[E, B] =
fab match {
case Valid(Left(a)) => ff.map(_(a))
case Valid(Right(b)) => Valid(b)
case i @ Invalid(_) => i
}

override def ap[A, B](ff: Validated[E, (A) => B])(fa: Validated[E, A]): Validated[E, B] =
fa.ap(ff)(Semigroup[E])
}

private[data] class ValidatedApplicative[E: Semigroup] extends CommutativeApplicative[Validated[E, *]] {
Expand Down

0 comments on commit 9079e16

Please sign in to comment.