Skip to content

Commit

Permalink
Use as rather than map and discard (#3708)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek authored Dec 8, 2020
1 parent 8e8be51 commit 7fd119d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
* }}}
*/
def productR[A, B](fa: F[A])(fb: F[B]): F[B] =
ap(map(fa)(_ => (b: B) => b))(fb)
ap(as(fa, { (b: B) => b }))(fb)

/**
* Compose two actions, discarding any value produced by the second.
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/FlatMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import scala.annotation.implicitNotFound
* scala> assert(count == 1)
* }}}
*/
def productLEval[A, B](fa: F[A])(fb: Eval[F[B]]): F[A] = flatMap(fa)(a => map(fb.value)(_ => a))
def productLEval[A, B](fa: F[A])(fb: Eval[F[B]]): F[A] = flatMap(fa)(a => as(fb.value, a))

@deprecated("Use productLEval instead.", "1.0.0-RC2")
@noop private[cats] def forEffectEval[A, B](fa: F[A])(fb: Eval[F[B]]): F[A] = productLEval(fa)(fb)
Expand Down Expand Up @@ -169,7 +169,7 @@ import scala.annotation.implicitNotFound
def foreverM[A, B](fa: F[A]): F[B] = {
// allocate two things once for efficiency.
val leftUnit = Left(())
val stepResult: F[Either[Unit, B]] = map(fa)(_ => leftUnit)
val stepResult: F[Either[Unit, B]] = as(fa, leftUnit)
tailRecM(())(_ => stepResult)
}

Expand Down
4 changes: 1 addition & 3 deletions core/src/main/scala/cats/Monad.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ import scala.annotation.implicitNotFound
val b = Eval.later(body)
tailRecM(())(_ =>
ifM(p)(
ifTrue = {
map(b.value)(_ => continue)
},
ifTrue = as(b.value, continue),
ifFalse = stop
)
)
Expand Down

0 comments on commit 7fd119d

Please sign in to comment.