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

Fix traverse for Either and Option #3000

Merged
merged 4 commits into from
Mar 29, 2023
Merged

Fix traverse for Either and Option #3000

merged 4 commits into from
Mar 29, 2023

Conversation

serras
Copy link
Member

@serras serras commented Mar 27, 2023

@nomisRev realized that our current implementations of traverse do not respect the expected laws. Let's compare with Haskell (where Just is the equivalent of Some, and [x] means listOf(x)).

> mapM (\x -> Just 3) (Left 2)
Just (Left 2)
> mapM (\x -> [3]) (Left 2)
[Left 2]

However, our current implementation would return None and an empty list in those cases. This PR implements the law-abiding implementations, which return Left wrapped in the corresponding type instead of the "error path" of those.

One important question here is whether we should consider this a bug, and thus just release the modifier implementation as part of 1.2.0, or whether this is a breaking change, and thus we should wait until 2.0 and release this fixed implementation under a different name.

Note: the implementation for Ior seems to be lawful.

@serras serras requested a review from nomisRev March 27, 2023 09:37
@github-actions
Copy link
Contributor

github-actions bot commented Mar 27, 2023

Kover Report

File Coverage [55.24%]
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt 57.00%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt 53.02%
Total Project Coverage 44.30%

@serras serras changed the title Fix traverse for Either Fix traverse for Either and Option Mar 27, 2023
Copy link
Collaborator

@franciscodr franciscodr left a comment

Choose a reason for hiding this comment

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

There are a few missing imports in the ReplaceWith expressions

franciscodr and others added 2 commits March 27, 2023 17:56
Co-authored-by: Francisco Diaz <francisco.d@47deg.com>
Copy link
Collaborator

@gutiory gutiory left a comment

Choose a reason for hiding this comment

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

Apart from @franciscodr suggestions, LGTM!

@serras serras requested a review from franciscodr March 28, 2023 15:47
Copy link
Collaborator

@franciscodr franciscodr left a comment

Choose a reason for hiding this comment

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

Thanks, @serras!

@serras serras merged commit ec7c08f into main Mar 29, 2023
@franciscodr franciscodr deleted the fix-traverse branch March 30, 2023 08:48
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.

3 participants