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

Possible bug with Either.Left short-circuiting #40

Open
Harmoniguy opened this issue Feb 14, 2025 · 1 comment
Open

Possible bug with Either.Left short-circuiting #40

Harmoniguy opened this issue Feb 14, 2025 · 1 comment

Comments

@Harmoniguy
Copy link
Contributor

I might be misunderstanding the intention, but I think I have found a bug in Either.

My understanding to the Either type is that Left should always short-circuit, as is stated in the readme.
However, as an example:
Either.left('x').app(Either.left('y'))
will result in:
Either.left('y')
rather than what I would expect:
Either.left('x')

As a sanity check I wrote what I understood to be the equivalent in Haskell:
Left 'x' <*> Left 'y'
which results in:
Left 'x'

In an effort to improve test coverage, I have altered the EitherTest apply property test to test for this case:

    @Property
    public void apply(char c, char d) {
        assertEquals(Either.right(String.valueOf(c)), Either.right(c).app(Either.right(Object::toString)));
        assertEquals(Either.left("fail"), Either.right(c).app(Either.left("fail")));
        assertEquals(Either.left(c), Either.left(c).app(Either.right(Object::toString)));

        Assume.assumeTrue(c != d);
        assertEquals(Either.left(c), Either.left(c).app(Either.left(d)));
    }

Please advise whether this is the intention, or if you would like I can open a PR with the test.

@jon-hanson
Copy link
Member

I think you're right - the Either.app implementation is bugged. I've committed a fix and have added your test (which now passes). Can you take a look.

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

No branches or pull requests

2 participants