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

Use as rather than map and discard #3708

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
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
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