-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
added leftNel
and rightNel
syntax
#2146
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package cats | ||
package syntax | ||
|
||
import cats.data.{EitherT, Ior, Validated, ValidatedNel} | ||
import cats.data.{EitherT, Ior, NonEmptyList, Validated, ValidatedNel} | ||
import scala.reflect.ClassTag | ||
import scala.util.{Failure, Success, Try} | ||
import EitherSyntax._ | ||
|
@@ -329,6 +329,31 @@ final class EitherIdOps[A](val obj: A) extends AnyVal { | |
|
||
/** Wrap a value in `Right`. */ | ||
def asRight[B]: Either[B, A] = Right(obj) | ||
|
||
/** | ||
* Wrap a value to a left EitherNel | ||
* | ||
* For example: | ||
* {{{ | ||
* scala> import cats.implicits._, cats.data.NonEmptyList | ||
* scala> "Err".leftNel[Int] | ||
* res0: Either[NonEmptyList[String], Int] = Left(NonEmptyList(Err)) | ||
* }}} | ||
*/ | ||
def leftNel[B]: Either[NonEmptyList[A], B] = Left(NonEmptyList.of(obj)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! @peterneyens addressed. |
||
|
||
/** | ||
* Wrap a value to a right EitherNel | ||
* | ||
* For example: | ||
* {{{ | ||
* scala> import cats.implicits._, cats.data.NonEmptyList | ||
* scala> 1.rightNel[String] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line also has an extra space |
||
* res0: Either[NonEmptyList[String], Int] = Right(1) | ||
* }}} | ||
*/ | ||
def rightNel[B]: Either[NonEmptyList[B], A] = Right(obj) | ||
|
||
} | ||
|
||
/** Convenience methods to use `Either` syntax inside `Either` syntax definitions. */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace error on the end of this line