diff --git a/core/src/main/scala/cats/data/OptionT.scala b/core/src/main/scala/cats/data/OptionT.scala index 75d77e18121..b02af3f9a76 100644 --- a/core/src/main/scala/cats/data/OptionT.scala +++ b/core/src/main/scala/cats/data/OptionT.scala @@ -39,6 +39,12 @@ final case class OptionT[F[_], A](value: F[Option[A]]) { case None => F.pure(None) }) + def transform[B](f: Option[A] => Option[B])(implicit F: Functor[F]): OptionT[F, B] = + OptionT(F.map(value)(f)) + + def subflatMap[B](f: A => Option[B])(implicit F: Functor[F]): OptionT[F, B] = + transform(_.flatMap(f)) + def getOrElse(default: => A)(implicit F: Functor[F]): F[A] = F.map(value)(_.getOrElse(default)) diff --git a/core/src/main/scala/cats/data/XorT.scala b/core/src/main/scala/cats/data/XorT.scala index 790f39289c4..15c2a6f4e42 100644 --- a/core/src/main/scala/cats/data/XorT.scala +++ b/core/src/main/scala/cats/data/XorT.scala @@ -61,6 +61,12 @@ case class XorT[F[_], A, B](value: F[A Xor B]) { def flatMapF[AA >: A, D](f: B => F[AA Xor D])(implicit F: Monad[F]): XorT[F, AA, D] = flatMap(f andThen XorT.apply) + def transform[C, D](f: Xor[A, B] => Xor[C, D])(implicit F: Functor[F]): XorT[F, C, D] = + XorT(F.map(value)(f)) + + def subflatMap[AA >: A, D](f: B => AA Xor D)(implicit F: Functor[F]): XorT[F, AA, D] = + transform(_.flatMap(f)) + def map[D](f: B => D)(implicit F: Functor[F]): XorT[F, A, D] = bimap(identity, f) def leftMap[C](f: A => C)(implicit F: Functor[F]): XorT[F, C, B] = bimap(f, identity)