Skip to content
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
27 changes: 26 additions & 1 deletion core/src/main/scala/cats/syntax/either.scala
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._
Expand Down Expand Up @@ -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.one(obj))

/**
* Wrap a value to a right EitherNel
*
* For example:
* {{{
* scala> import cats.implicits._, cats.data.NonEmptyList
* scala> 1.rightNel[String]
* 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. */
Expand Down