Skip to content

Xor.Right.right() should return Optional.ofNullable(right) #308

Open

Description

@JimSermersheim

I have a minion function that can in some conditions return None.
When this happens, the Result element for the minion is a Result(null) -- in other words, The Result's xor is a Right, where the right value is null. Calling Result.result() causes a NullPointerException because Xor.Right.right() is returning Optional.of(right). Since it's returning an Optional, it seems like it'd be better to return Optional.ofNullable(right).

The same would probably apply to Xor.Left.left(), though I can't think of the use case where the value there would be null.

Activity

  1. JimSermersheim commented on Aug 2, 2023

    @JimSermersheim
    Author

    Workaround: don't' call Result.result(). Instead, use Result.consume(). The consumerResult will be given a null object for the case in the description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions