Skip to content

Commit

Permalink
Add validated and validatedNec to boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoMeijer authored Feb 28, 2022
1 parent ef910b6 commit 38ea816
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion shared/src/main/scala/mouse/boolean.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mouse

import cats.data.{EitherNel, NonEmptyList, Validated, ValidatedNel}
import cats.data.{EitherNel, NonEmptyList, Validated, ValidatedNec, ValidatedNel}
import cats.{Applicative, ApplicativeError, Monoid}
import mouse.BooleanSyntax.LiftToPartiallyApplied

Expand All @@ -22,6 +22,12 @@ final class BooleanOps(private val b: Boolean) extends AnyVal {
@inline def either[L, R](l: => L, r: => R): Either[L, R] = fold(Right(r), Left(l))

@inline def eitherNel[L, R](ifFalse: => L, ifTrue: => R): EitherNel[L, R] = either(NonEmptyList.one(ifFalse), ifTrue)

@inline def validated[L, R](ifFalse: => L, ifTrue: => R): Validated[L, R] =
fold(Validated.valid(ifTrue), Validated.invalid(ifFalse))

@inline def validatedNec[L, R](ifFalse: => L, ifTrue: => R): ValidatedNec[L, R] =
fold(Validated.validNec(ifTrue), Validated.invalidNec(ifFalse))

@inline def validatedNel[L, R](ifFalse: => L, ifTrue: => R): ValidatedNel[L, R] =
fold(Validated.validNel(ifTrue), Validated.invalidNel(ifFalse))
Expand Down

0 comments on commit 38ea816

Please sign in to comment.