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

rename traverseX and sequenceX for Iterable #2692

Merged
merged 20 commits into from Mar 23, 2022
Merged

Conversation

i-walker
Copy link
Member

@i-walker i-walker commented Mar 16, 2022

for parTraverse I'll add another PR since this needs a bit of investigating

@i-walker
Copy link
Member Author

For parTraverse I will provide an example repo and leave a comment https://youtrack.jetbrains.com/issue/KT-49658 where it is failing

@i-walker i-walker requested a review from a team March 16, 2022 09:11
@nomisRev
Copy link
Member

The issue you linked @i-walker isn't the ticket what is causing issue with parTraverse.

parTraverse for suspend (A) -> B conflicts with any other lambda having a data type in it's return type. Since here B can be Either<?, ?> or any other data type.

If we would rename parTraverse to parMap for suspend (A) -> B that solves the problem, but renaming the other parTraverse results in the following bug. https://youtrack.jetbrains.com/issue/KT-43907
So we can currently not rename parTraverseXXX to parTraverse yet, we can however already consider renaming parTraverse to parMap for suspend (A) -> B. But let's take that into another PR.

We should create a ticket for this deprecation, and work when the above issue in Kotlin is fixed.


@OptIn(ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
public inline fun <A, B> Iterable<A>.traverse(f: (A) -> B?): List<B>? {
Copy link
Member

Choose a reason for hiding this comment

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

Curious that this doesn't conflict with the other traverse functions 🤔
This seems like one of those signatures that breaks all other functions 😅

What happens in the case of:

fun either(i: Int): Either<String, Int>? = null

val x: ??? = listOf(1, 2, 3).traverse { either(i) }

I guess ??? here is List<Either<String, Int>>?, and to turn it into Either<String, List<Int>>? we'd need to chain it with ?.sequence(). That'd be pretty cool if that works like that out of the box.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this one would be List<Either<String, Int>>? I can set up a small example test

@pakoito
Copy link
Member

pakoito commented Mar 16, 2022

These are some of the coolest functions in the lib, would it possible to save them in some form? 🥺

i-walker and others added 9 commits March 16, 2022 12:29
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
…erable.kt

Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
@nomisRev
Copy link
Member

@pakoito not sure what you mean?
Not of this functionality is being removed, we're trying to simplify the naming from traverseXXX to traverse. All functionality is being preserved.

The only "big" change that is happening is that we're changing the signature from Sequence#traverse to return List instead of Sequence because it's actually a ListSequence under the hood. So we felt that returning Either<E, Sequence<A>> is a lie and it should be returning Either<E, List<A>> to be more correct.

@pakoito
Copy link
Member

pakoito commented Mar 16, 2022

Gotcha!

i-walker and others added 2 commits March 16, 2022 14:03
Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
@i-walker i-walker requested a review from nomisRev March 16, 2022 13:07
@i-walker i-walker changed the title deprecate traverseX and sequenceX for Iterable reame traverseX and sequenceX for Iterable Mar 16, 2022
@i-walker i-walker changed the title reame traverseX and sequenceX for Iterable rename traverseX and sequenceX for Iterable Mar 16, 2022
Copy link
Member

@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.

Looks great to me @i-walker! Awesome clean-up. Now all methods are simply traverse and sequence and the compiler automatically picks the correct one 🥳

}
}

"sequence Either traverse Nullable interoperate - and proof map + sequence equality with traverse" {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks, @i-walker! This is pretty cool that it works out of the box!

@nomisRev nomisRev requested review from pakoito and a team March 21, 2022 08:18
Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

thanks @i-walker

@i-walker i-walker merged commit 3540e3d into main Mar 23, 2022
@i-walker i-walker deleted the is-traverse-Iterable branch March 23, 2022 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants