Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an overload of FlatMapOps#>> that gives control on the evaluation… #492

Merged
merged 1 commit into from
Sep 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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