-
Notifications
You must be signed in to change notification settings - Fork 451
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
Overload Arrow FX ParZip for tupling #2821 #2900
Conversation
Oof, that is really bad 😞 but a bit strange since the lambda doesn't match 🤔 |
Sorry, I don't follow...
Yes, if I wanted to target the non-triple-returning |
@raulraja asked for a sample that illustrates the overload resolution ambiguity of fun <A, B> f(fa: () -> A, f: (A) -> B): B = TODO()
fun <A, B> f(fa: () -> A, fb: () -> B): Pair<A, B> = TODO()
// Compiler errors
val r1 = f({ 1 }, { "one" })
val r2: Pair<Int, String> = f({ 1 }, { "one" })
val r3: String = f({ 1 }, { "one" })
// OK
val r4 = f({ 1 }, f = { "one" })
val r5 = f({ 1 }, fb = { "one" })
val r6 = f({ 1 }, { _ -> "one" })
val r7 = f({ 1 }, { -> "one" }) If the parameters Here's the compiler error:
Per Raul's suggestion, I tried applying |
fun <A, B> f(fa: () -> A, f: (A) -> B): B = TODO()
fun <A, B> f(fa: () -> A, fb: () -> B): Pair<A, B> = TODO() These are not good examples, and don't occur in I don't think we can release this improvement if you need to specify the lambda name, the goal of this new API was to simplify the API in case you don't want to provide a cc\ @StylianosGakis originally proposed this API on KotlinLang. WDYT? |
@nomisRev Sorry, I don't understand. If there's no ambiguity between |
Sorry, maybe I didn't phrase myself well. What I was trying the say is the following: The Kotlin compiler can infer This is however not the case for For this reason I was under the impression that these functions could co-exist: fun <A, B, C> f(fa: () -> A, fb: () -> B, f: (A, B) -> C): C = TODO()
fun <A, B, C> f(fa: () -> A, fb: () -> B, fc: () -> C): Triple<A, B, C> = TODO() Since |
Or, one can also explicitly specify the lambda parameters. |
They can co-exist. It's at the call-points that the error occurs, not at the definitions of the functions. That said, the situation is not ideal for an API. |
Right, that's what I meant. It can co-exists at the definition site, but it cannot co-exists from the caller side. Requiring to specify lambda parameter name is very foreign in Kotlin. I think one of the more annoying parts is also that it Kotlin cannot ignore an unused |
Oof, that's just so unfortunate. parZip(
{ ... },
{ ... },
) { _, _ -> } on the call-site is gonna have to suffice in this case. I don't have any better ideas atm personally. |
Agreed
Only alternative is introducing an different name,
Thank you for the feedback @StylianosGakis |
@lgtout we've discussed this PR during the biweekly Arrow meeting, and we've agreed to keep By the way, we also talked about the name. |
@serras Thanks for the update. No problem. I'm happy to make the change to |
Support Pair, Triple, and Tuple4-9 return types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think .gradletasknamecache
is incorrectly checked in? 🤔 It adds 6,434
lines 😱
If this is an optimisation for Gradle, can we move it to a separate PR? And could you please clarify how it works 😅 🙏 It's the first time I've seen it.
2 small comments:
- We avoid star-imports in Kotlin
- One suggestions to improve documentation
☺️
Thanks for the great work @lgtout!! 🙏 🥳
@@ -0,0 +1,338 @@ | |||
package arrow.fx.coroutines | |||
|
|||
import arrow.core.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We avoid star-imports in the Arrow codebase.
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTupled.kt
Show resolved
Hide resolved
@@ -1,5 +1,6 @@ | |||
package arrow.fx.coroutines | |||
|
|||
import arrow.core.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid star imports.
Oops! Yes No problem re the other changes. I'll make them and resubmit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect @lgtout! Thank you so much for this contribution! 🙌 🥳
The one weird thing I need to call out is that there's ambiguity between the overloads of ParZip, as currently implemented.
For example:
causes problems for the compiler because it can't tell if we intend to call this:
or this:
In the KNIT examples I added, I disambiguated this way:
to select for the
Triple
-returning override.This would work, too:
Neither seem ideal, so please provide guidance on whether or how to improve this.
Thank you!