Skip to content
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