Skip to content

Commit

Permalink
Merge pull request #770 from dwijnand/OptionT-flatMap
Browse files Browse the repository at this point in the history
Rewrite OptionT.flatMap in terms of flatMapF
  • Loading branch information
ceedubs committed Jan 2, 2016
2 parents 213aab0 + b07823f commit 6253277
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/NotNull.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object NotNull {

private[this] def ambiguousException: Exception = new Exception("An instance of NotNull[Null] was used. This should never happen. Both ambiguous NotNull[Null] instances should always be in scope if one of them is.")

implicit def `If you are seeing this, you probably need to add an explicit type parameter somewhere, beause Null is being inferred.`: NotNull[Null] = throw ambiguousException
implicit def `If you are seeing this, you probably need to add an explicit type parameter somewhere, because Null is being inferred.`: NotNull[Null] = throw ambiguousException

implicit def ambiguousNull2: NotNull[Null] = throw ambiguousException

Expand Down
12 changes: 2 additions & 10 deletions core/src/main/scala/cats/data/OptionT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ final case class OptionT[F[_], A](value: F[Option[A]]) {
OptionT(F.map(value)(_.map(f)))

def flatMap[B](f: A => OptionT[F, B])(implicit F: Monad[F]): OptionT[F, B] =
OptionT(
F.flatMap(value){
case Some(a) => f(a).value
case None => F.pure(None)
})
flatMapF(a => f(a).value)

def flatMapF[B](f: A => F[Option[B]])(implicit F: Monad[F]): OptionT[F, B] =
OptionT(
Expand Down Expand Up @@ -76,11 +72,7 @@ final case class OptionT[F[_], A](value: F[Option[A]]) {
F.map(value)(_.isEmpty)

def orElse(default: => OptionT[F, A])(implicit F: Monad[F]): OptionT[F, A] =
OptionT(
F.flatMap(value) {
case s @ Some(_) => F.pure(s)
case None => default.value
})
orElseF(default.value)

def orElseF(default: => F[Option[A]])(implicit F: Monad[F]): OptionT[F, A] =
OptionT(
Expand Down

0 comments on commit 6253277

Please sign in to comment.