Skip to content

Commit

Permalink
align type parameter of smart constructor with Validated (#2525) (#2527)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTriple authored and Luka Jacobowitz committed Sep 24, 2018
1 parent e5a6c91 commit 2388287
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -521,48 +521,48 @@ private[data] class ValidatedApplicative[E: Semigroup] extends CommutativeApplic

private[data] trait ValidatedFunctions {
/**
* Converts an `A` to a `Validated[A, B]`.
* Converts an `E` to a `Validated[E, A]`.
*
* For example:
* {{{
* scala> Validated.invalid[IllegalArgumentException, String](new IllegalArgumentException("Argument is nonzero"))
* res0: Validated[IllegalArgumentException, String] = Invalid(java.lang.IllegalArgumentException: Argument is nonzero)
* }}}
*/
def invalid[A, B](a: A): Validated[A, B] = Validated.Invalid(a)
def invalid[E, A](e: E): Validated[E, A] = Validated.Invalid(e)

/**
* Converts an `A` to a `ValidatedNel[A, B]`.
* Converts an `E` to a `ValidatedNel[E, A]`.
*
* For example:
* {{{
* scala> Validated.invalidNel[IllegalArgumentException, String](new IllegalArgumentException("Argument is nonzero"))
* res0: ValidatedNel[IllegalArgumentException, String] = Invalid(NonEmptyList(java.lang.IllegalArgumentException: Argument is nonzero))
* }}}
*/
def invalidNel[A, B](a: A): ValidatedNel[A, B] = Validated.Invalid(NonEmptyList(a, Nil))
def invalidNel[E, A](e: E): ValidatedNel[E, A] = Validated.Invalid(NonEmptyList(e, Nil))

/**
* Converts a `B` to a `Validated[A, B]`.
* Converts a `A` to a `Validated[E, A]`.
*
* For example:
* {{{
* scala> Validated.valid[IllegalArgumentException, String]("Hello world")
* res0: Validated[IllegalArgumentException, String] = Valid(Hello world)
* }}}
*/
def valid[A, B](b: B): Validated[A, B] = Validated.Valid(b)
def valid[E, A](a: A): Validated[E, A] = Validated.Valid(a)

/**
* Converts a `B` to a `ValidatedNel[A, B]`.
* Converts a `A` to a `ValidatedNel[E, A]`.
*
* For example:
* {{{
* scala> Validated.validNel[IllegalArgumentException, String]("Hello world")
* res0: ValidatedNel[IllegalArgumentException, String] = Valid(Hello world)
* }}}
*/
def validNel[A, B](b: B): ValidatedNel[A, B] = Validated.Valid(b)
def validNel[E, A](a: A): ValidatedNel[E, A] = Validated.Valid(a)

def catchNonFatal[A](f: => A): Validated[Throwable, A] =
try {
Expand Down Expand Up @@ -596,18 +596,18 @@ private[data] trait ValidatedFunctions {
def fromIor[A, B](ior: Ior[A, B]): Validated[A, B] = ior.fold(invalid, valid, (_, b) => valid(b))

/**
* If the condition is satisfied, return the given `B` as valid,
* otherwise return the given `A` as invalid.
* If the condition is satisfied, return the given `A` as valid,
* otherwise return the given `E` as invalid.
*/
final def cond[A, B](test: Boolean, b: => B, a: => A): Validated[A, B] =
if (test) valid(b) else invalid(a)
final def cond[E, A](test: Boolean, a: => A, e: => E): Validated[E, A] =
if (test) valid(a) else invalid(e)

/**
* If the condition is satisfied, return the given `B` as valid NEL,
* otherwise return the given `A` as invalid NEL.
* If the condition is satisfied, return the given `A` as valid NEL,
* otherwise return the given `E` as invalid NEL.
*/
final def condNel[A, B](test: Boolean, b: => B, a: => A): ValidatedNel[A, B] =
if (test) validNel(b) else invalidNel(a)
final def condNel[E, A](test: Boolean, a: => A, e: => E): ValidatedNel[E, A] =
if (test) validNel(a) else invalidNel(e)
}

private[data] trait ValidatedFunctionsBinCompat0 {
Expand Down

0 comments on commit 2388287

Please sign in to comment.