Skip to content

Commit

Permalink
Add an overload of FlatMapOps#>> that gives control on the evaluation…
Browse files Browse the repository at this point in the history
… strategy of the second action
  • Loading branch information
julienrf committed Sep 7, 2015
1 parent 672e010 commit b5718ae
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion core/src/main/scala/cats/syntax/flatMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit b5718ae

Please sign in to comment.