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

Replace parTupled with parZipOrAccumulate #2957

Merged
merged 6 commits into from
Mar 27, 2023
Merged

Conversation

nomisRev
Copy link
Member

@nomisRev nomisRev commented Mar 3, 2023

This week I had a discussion with @lgtout about parTupled. We were originally on the fence to add parTupled in #2900 due to signature conflicts with parZip.

Whilst writing some examples, and documentation I encountered issues with parTupled where the current signatures are also not valid. It cannot be resolved without explicitely specifying context: CoroutineContext parameter. After some discussion with @lgtout on Kotlin Slack, https://kotlinlang.slack.com/archives/C8UK6RTHU/p1677616555972749 we came to a mutual conclusion it's maybe not worth adding it since it requires an additional 9 methods. Total of 18 methods to provide something that practically already exists in parZip.

Whilst working on some other documentation about accumulating parallel errors I realised that we only provide an API for this over Iterable but not zipping independent operations.

This PR proposes a small convenience API to cover that use-case.

@lgtout If everyone agrees on this API are you interested in continuing this work? I only played out the arity-2 signatures, and you're already familiar with the layout of Arrow Fx Coroutines + parZip so I thought this might be a good ticket for you to work on if you're interested. I can close this PR, or feel free to work on this branch directly. Whatever would work better for you ☺️

@nomisRev nomisRev added help wanted discussion 1.2.0 Tickets belonging to 1.1.2 labels Mar 3, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

Kover Report

File Coverage [0.00%]
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZipOrAccumulate.kt 0.00%
Total Project Coverage 44.18%

Comment on lines 22 to 23
crossinline fa: suspend ScopedRaise<E>.() -> A,
crossinline fb: suspend ScopedRaise<E>.() -> B,
Copy link
Member Author

Choose a reason for hiding this comment

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

This can still benefit from the ScopedAccumulatingRaise type from #2952, and makes me wonder if Either.zipOrAccumulate shouldn't be DSL based as well to support both E and Nel<E> in a single API. 🤔

Currently we support both Either and EitherNel separately, and they both types don't interop with each-other.

@lgtout
Copy link
Collaborator

lgtout commented Mar 3, 2023

Thanks, @nomisRev. I'm happy to continue working on this, using this branch.

@serras
Copy link
Member

serras commented Mar 24, 2023

@nomisRev @lgtout as I understand from the commits, this PR is ready to merge, right?

@lgtout
Copy link
Collaborator

lgtout commented Mar 24, 2023

@serras I just need to add docs and Knit examples. Do my code changes look okay?

Copy link
Member

@serras serras left a comment

Choose a reason for hiding this comment

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

LGTM, @lgtout Thanks for the contribution!

@nomisRev nomisRev marked this pull request as ready for review March 26, 2023 17:24
Copy link
Member Author

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you so much @lgtout 🙌 🥳

I think we can move ahead and merge this already, you can add a document with Knit examples later-on. Or perhaps directly in the new website. WDYT @serras? I cannot approve my own PR, but I've upgraded it to ready-to-review and tagged some reviewers ☺️

@lgtout
Copy link
Collaborator

lgtout commented Mar 26, 2023

@nomisRev Ok. Sounds good regarding adding docs and examples later on.

@serras
Copy link
Member

serras commented Mar 27, 2023

@nomisRev I'm working on the docs right now so we don't forget. I've already approved, we need somebody else from the team to give the green check.

@nomisRev
Copy link
Member Author

@lgtout it's been added directly in the new website. So I don't think we need elaborate documentation on this API here. Perhaps linking to zipOrAccumulate and parZip and mentioning it combines both functionalities?

I am merging this PR already, a PR adding minimal documentation is welcome but not blocking for the RC release.

@nomisRev nomisRev merged commit eb19a0f into main Mar 27, 2023
@nomisRev nomisRev deleted the sv-parZipOrAccumulate branch March 27, 2023 09:02
serras added a commit to arrow-kt/arrow-website that referenced this pull request Mar 27, 2023
Including a reference to the parallel versions as requested in
arrow-kt/arrow#2957

---------

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.2.0 Tickets belonging to 1.1.2 discussion help wanted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants