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 8, 2015
1 parent 672e010 commit 5a9b587
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 [[followedBy]]. */
@inline final def >> [B](fb: F[B]): F[B] = followedBy(fb)

/** Sequentially compose two actions, discarding any value produced by the first. */
def followedBy[B](fb: F[B]): F[B] = F.flatMap(fa)(_ => fb)

/**
* Sequentially compose two actions, discarding any value produced by the first. This variant of
* [[followedBy]] 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.followedByEval(later(fb))
* }}}
*/
def followedByEval[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 5a9b587

Please sign in to comment.