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

["Request"] Improve Iterable extension impl #2812

Closed
raulraja opened this issue Sep 1, 2022 · 3 comments
Closed

["Request"] Improve Iterable extension impl #2812

raulraja opened this issue Sep 1, 2022 · 3 comments

Comments

@raulraja
Copy link
Member

raulraja commented Sep 1, 2022

Some of our Iterable extensions, such as partitionEither have non-optimal implementations that can be easily fixed to produce fewer allocations and iterations.

public fun <A, B> Iterable<Either<A, B>>.separateEither(): Pair<List<A>, List<B>> {

Discussion with Mitchell Cohen from slack regarding partitionEither examples: https://kotlinlang.slack.com/archives/C5UPMM0A0/p1662064718102909?thread_ts=1559561395.141900&cid=C5UPMM0A0

@Khepu
Copy link
Contributor

Khepu commented Sep 2, 2022

The exact same pattern is followed here:

public fun <A, B> Iterable<Validated<A, B>>.separateValidated(): Pair<List<A>, List<B>> {

This also applies to Sequence and Option, would changes for all of those be included in the same PR?

Tests for these methods are lacking from what I could tell, would it make sense to create those?

@raulraja
Copy link
Member Author

raulraja commented Sep 2, 2022

This also applies to Sequence and Option, would changes for all of those be included in the same PR?

that would be great

Tests for these methods are lacking from what I could tell, would it make sense to create those?

yes, that'd be great, thanks!

@nomisRev
Copy link
Member

nomisRev commented Sep 2, 2022

Hey @Khepu,

Tests for these methods are lacking from what I could tell, would it make sense to create those?

Yes, that would be greatly appreciated 🙏 There is some tests missing here, and there but we're trying to fill them in over time whenever we have to touch related code.

This also applies to Sequence and Option, would changes for all of those be included in the same PR?

Yes, you can include separateValidated and both methods for Sequence as well. I'm not sure this applies to Option, since Option only holds a single value, but I'm not sure which methods you're referring to.

Also feel free to put it in a separate PR if that is easier for you.

nomisRev added a commit that referenced this issue Sep 12, 2022
Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
nomisRev added a commit that referenced this issue Oct 17, 2022
* Refactor: Use fold to separate Sequence of Either
* Refactor: Use fold to separate Sequence of Validated
* Feature: Add tests for separating Either & Validated

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
Co-authored-by: Imran Malic Settuba <46971368+i-walker@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants