Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add Bifunctor[λ[(A, B) => F[G[A, B]]]] instance for F[_]: Functor and G[_, _]: Bifunctor #4362

Merged
merged 1 commit into from
Jan 23, 2023

Conversation

bpholt
Copy link
Member

@bpholt bpholt commented Dec 29, 2022

Motivated by the desire to leftMap on a tuple inside an effect, e.g.

val fab: F[(A, B)] = ???
val f: A => C = ???
Bifunctor[λ[(A, B) => F[(A, B)]]].leftMap(fab)(f) // returns F[(C, B)]

If folks aren't comfortable adding this kind of instance, it'd be pretty easy to implement this via a new wrapper class, similar to Binested. AFAICT Bifunctor[λ[(A, B) => F[G[A, B]]]] is lawful, but it doesn't infer very well—I don't think you can summon it using the syntax enhancements (e.g. Option("a" -> "b").leftMap(_.length) doesn't work, but Bifunctor[λ[(A, B) => Option[(A, B)]]].leftMap(Option("a" -> "b"))(_.length) should). Or, we could add both this instance and a new wrapper class.

Just for clarity, cats already has Binested, but its type parameters are the wrong shape for this use case—it has F[_, _], G[_], and H[_] for F[G[A], H[B]], but we need F[_] and G[_, _] for F[G[A, B]].

If we decide not to merge this and want to move forward with a new wrapper, I'll follow up with a new PR.

@armanbilge armanbilge closed this Jan 6, 2023
@armanbilge armanbilge reopened this Jan 6, 2023
@bpholt
Copy link
Member Author

bpholt commented Jan 6, 2023

Test failure:

==> X cats.jvm.tests.FutureSuite.Future: coflatMap.coflatMap associativity  3.016s munit.FailException: Failing seed: MmYbi6iubz6pfqBmHMelFTp6hvWvRl5jlEXAkOtr4SC=
You can reproduce this failure by adding the following override to your suite:

  override val scalaCheckInitialSeed = "MmYbi6iubz6pfqBmHMelFTp6hvWvRl5jlEXAkOtr4SC="

Exception raised on property evaluation.
> ARG_0: Future(Failure(java.lang.Exception))
> ARG_1: org.scalacheck.GenArities$$Lambda$263/0x0000000800e04de8@640d0f70
> ARG_2: org.scalacheck.GenArities$$Lambda$263/0x0000000800e04de8@6e9436d8
> Exception: java.util.concurrent.TimeoutException: Future timed out after [3 seconds]
    at munit.ScalaCheckSuite.propToTry(ScalaCheckSuite.scala:98)

Caused by: java.util.concurrent.TimeoutException: Future timed out after [3 seconds]
    at scala.concurrent.impl.Promise$DefaultPromise.tryAwait0(Promise.scala:248)
    at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:261)
    at scala.concurrent.Await$.$anonfun$result$1(package.scala:201)
    at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:62)
    at scala.concurrent.Await$.result(package.scala:124)
    at cats.jvm.tests.FutureSuite.cats$jvm$tests$FutureSuite$$$anonfun$eqfa$1(FutureSuite.scala:45)

This failure seems unlikely to be related to this PR. @armanbilge I saw you just triggered a rebuild; are you still working on CI? If so, I'll let this simmer for a bit.

@armanbilge
Copy link
Member

are you still working on CI

Well I was hoping I was done 😂 this looks like a JVM flake.

@bpholt
Copy link
Member Author

bpholt commented Jan 6, 2023

Darn. Well, I can rerun the action if you think it's just a flake. Looks like you already restarted it

@bpholt
Copy link
Member Author

bpholt commented Jan 6, 2023

Looks like it worked! Thanks for fixing the Native issues @armanbilge!

Copy link
Contributor

@satorg satorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@johnynek johnynek merged commit 3eced3b into typelevel:main Jan 23, 2023
@armanbilge armanbilge changed the title add Bifunctor[λ[(A, B) => F[G[A, B]]]] instance for F[_]: Functor and G[_, _]: Bifunctor add Bifunctor[λ[(A, B) => F[G[A, B]]]] instance for F[_]: Functor and G[_, _]: Bifunctor Jan 23, 2023
@bpholt bpholt deleted the bifunctor-in-functor branch August 11, 2023 17:13
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants