Skip to content
Closed
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
6 changes: 6 additions & 0 deletions core/src/main/scala/cats/Monad.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ trait Monad[F[_]] extends FlatMap[F] with Applicative[F] {
tailRecM(branches.toList)(step)
}

def whenM[A](cond: F[Boolean])(f: => F[A]): F[Unit] =
ifM(cond)(ifTrue = void(f), ifFalse = unit)

def unlessM[A](cond: F[Boolean])(f: => F[A]): F[Unit] =
ifM(cond)(ifTrue = unit, ifFalse = void(f))

/**
* Modifies the `A` value in `F[A]` with the supplied function, if the function is defined for the value.
* Example:
Expand Down