From a23da34a72a3ebecf698d9ee5478101c75349312 Mon Sep 17 00:00:00 2001 From: Edmund Noble Date: Fri, 12 May 2017 19:16:06 -0400 Subject: [PATCH] Doctests --- core/src/main/scala/cats/data/Validated.scala | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/src/main/scala/cats/data/Validated.scala b/core/src/main/scala/cats/data/Validated.scala index 2bbd85f9b4..725699d47a 100644 --- a/core/src/main/scala/cats/data/Validated.scala +++ b/core/src/main/scala/cats/data/Validated.scala @@ -425,12 +425,48 @@ private[data] sealed abstract class ValidatedInstances2 { } private[data] trait ValidatedFunctions { + /** + * Converts an `A` to a `Validated[A, B]`. + * + * 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) + /** + * Converts an `A` to a `ValidatedNel[A, B]`. + * + * 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)) + /** + * Converts a `B` to a `Validated[A, B]`. + * + * 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) + /** + * Converts a `B` to a `ValidatedNel[A, B]`. + * + * 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 catchNonFatal[A](f: => A): Validated[Throwable, A] =