diff --git a/core/src/main/scala/cats/syntax/flatMap.scala b/core/src/main/scala/cats/syntax/flatMap.scala index 7161c11b2cd..f4d6c0653ca 100644 --- a/core/src/main/scala/cats/syntax/flatMap.scala +++ b/core/src/main/scala/cats/syntax/flatMap.scala @@ -21,7 +21,24 @@ class FlatMapOps[F[_], A](fa: F[A])(implicit F: FlatMap[F]) { def flatMap[B](f: A => F[B]): F[B] = F.flatMap(fa)(f) def mproduct[B](f: A => F[B]): F[(A, B)] = F.mproduct(fa)(f) def >>=[B](f: A => F[B]): F[B] = F.flatMap(fa)(f) - def >>[B](fb: F[B]): F[B] = F.flatMap(fa)(_ => fb) + + /** Alias for [[andAfter]]. */ + @inline final def >> [B](fb: F[B]): F[B] = andAfter(fb) + + /** Sequentially compose two actions, discarding any value produced by the first. */ + def andAfter[B](fb: F[B]): F[B] = F.flatMap(fa)(_ => fb) + + /** + * Sequentially compose two actions, discarding any value produced by the first. This overload also lets you + * define the evaluation strategy of the second action. For instance you can evaluate it only ''after'' + * the first action has finished: + * + * {{{ + * fa.andAfterEval(later(fb)) + * }}} + */ + def andAfterEval[B](fb: Eval[F[B]]): F[B] = F.flatMap(fa)(_ => fb.value) + } class FlattenOps[F[_], A](ffa: F[F[A]])(implicit F: FlatMap[F]) {