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

Replaces other Applicative.pure(()) with .unit #4558

Merged
merged 1 commit into from
Feb 4, 2024
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
14 changes: 7 additions & 7 deletions free/src/test/scala/cats/free/FreeTSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class FreeTSuite extends CatsSuite {
checkAll("FreeT[Option, Option, Int", DeferTests[FreeTOption].defer[Int])

test("FlatMap stack safety tested with 50k flatMaps") {
val expected = Applicative[FreeTOption].pure(())
val expected = Applicative[FreeTOption].unit
val result =
Monad[FreeTOption].tailRecM(0)((i: Int) =>
if (i < 50000)
Expand All @@ -85,17 +85,17 @@ class FreeTSuite extends CatsSuite {
}

test("Stack safe with 50k left-associated flatMaps") {
val expected = Applicative[FreeTOption].pure(())
val expected = Applicative[FreeTOption].unit
val result =
(0 until 50000).foldLeft(Applicative[FreeTOption].pure(()))((fu, i) =>
(0 until 50000).foldLeft(Applicative[FreeTOption].unit)((fu, i) =>
fu.flatMap(u => Applicative[FreeTOption].pure(u))
)

assert(Eq[FreeTOption[Unit]].eqv(expected, result))
}

test("Stack safe with flatMap followed by 50k maps") {
val expected = Applicative[FreeTOption].pure(())
val expected = Applicative[FreeTOption].unit
val result =
(0 until 50000).foldLeft(().pure[FreeTOption].flatMap(_.pure[FreeTOption]))((fu, i) => fu.map(identity))

Expand All @@ -110,7 +110,7 @@ class FreeTSuite extends CatsSuite {
}

test("mapK stack-safety") {
val a = (0 until 50000).foldLeft(Applicative[FreeTOption].pure(()))((fu, i) =>
val a = (0 until 50000).foldLeft(Applicative[FreeTOption].unit)((fu, i) =>
fu.flatMap(u => Applicative[FreeTOption].pure(u))
)
val b = a.mapK(FunctionK.id)
Expand All @@ -126,7 +126,7 @@ class FreeTSuite extends CatsSuite {
}

test("compile stack-safety") {
val a = (0 until 50000).foldLeft(Applicative[FreeTOption].pure(()))((fu, i) =>
val a = (0 until 50000).foldLeft(Applicative[FreeTOption].unit)((fu, i) =>
fu.flatMap(u => Applicative[FreeTOption].pure(u))
)
val b = a.compile(FunctionK.id) // used to overflow
Expand All @@ -147,7 +147,7 @@ class FreeTSuite extends CatsSuite {
type F[A] = FreeT[Id, Option, A]
val F = MonadError[F, Unit]

val eff = F.flatMap(F.pure(()))(_ => F.raiseError[String](()))
val eff = F.flatMap(F.unit)(_ => F.raiseError[String](()))
assert(F.attempt(eff).runM(Some(_)) === Some(Left(())))
}

Expand Down
4 changes: 2 additions & 2 deletions laws/src/main/scala/cats/laws/ApplicativeLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ trait ApplicativeLaws[F[_]] extends ApplyLaws[F] {
// Semigroupal's associativity law.

def monoidalLeftIdentity[A](fa: F[A]): (F[(Unit, A)], F[A]) =
(F.product(F.pure(()), fa), fa)
(F.product(F.unit, fa), fa)

def monoidalRightIdentity[A](fa: F[A]): (F[(A, Unit)], F[A]) =
(F.product(fa, F.pure(())), fa)
(F.product(fa, F.unit), fa)
}

object ApplicativeLaws {
Expand Down