Skip to content

Commit

Permalink
ApplicativeError: add raiseOption operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
diesalbla committed Mar 20, 2020
1 parent f28136c commit 92031da
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,27 @@ trait ApplicativeError[F[_], E] extends Applicative[F] {
case None => raiseError(ifEmpty)
}

/**
* Convert from scala.Option when the content is a value of the error type.
* If the option is empty, an empty unit effect is given.
* If the option contains an error, it is raised.
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.ApplicativeError
* scala> val F = ApplicativeError[Either[String, *], String]
*
* scala> F.raiseOption(Option.empty[String])
* res0: scala.Either[String, Unit] = Right(())
*
* scala> F.raiseOption(Option("Failed"))
* res1: scala.Either[String, Unit] = Left("Failed")
* }}}
*/
def raiseOption(oe: Option[E]): F[Unit] =
oe.fold(unit)(raiseError)

/**
* Convert from cats.data.Validated
*
Expand Down

0 comments on commit 92031da

Please sign in to comment.