Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align type parameter of smart constructor with Validated (#2525) #2527

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -514,48 +514,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 @@ -589,16 +589,16 @@ 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)
}