Skip to content

[wpiutil java] Add an Option type - #9290

Open
SamCarlberg wants to merge 2 commits into
wpilibsuite:mainfrom
SamCarlberg:java-adt
Open

[wpiutil java] Add an Option type#9290
SamCarlberg wants to merge 2 commits into
wpilibsuite:mainfrom
SamCarlberg:java-adt

Conversation

@SamCarlberg

@SamCarlberg SamCarlberg commented Aug 15, 2026

Copy link
Copy Markdown
Member

Uses an ADT with subtypes Some(T) and None(), following typical naming practices from other languages

Key difference from java.util.Optional is that there's no unsafe get() method that can be called. getOrThrow() exists to make it clear that an exception will be thrown if there's no value. Users can also use pattern matching instanceof or switch expressions on the ADT types, which j.u.Optional does not provide.

Closes #7447

Uses an ADT with subtypes `Some(T)` and `None()`, following typical naming practices from other languages

Key difference from `java.util.Optional` is that there's no unsafe `get()` method that can be called. `getOrThrow()` exists to make it clear that an exception will be thrown if there's no value. Users can also use pattern matching instanceof or switch expressions on the ADT types, which j.u.Optional does not provide.
@github-actions github-actions Bot added component: wpiutil Utility library type: testing Related to testing. labels Aug 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4de71048f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread wpiutil/src/main/java/org/wpilib/util/option/Option.java Outdated
Comment thread wpiutil/src/main/java/org/wpilib/util/option/Option.java Outdated
Comment thread wpiutil/src/main/java/org/wpilib/util/option/Some.java
Comment thread wpiutil/src/main/java/org/wpilib/util/option/Some.java
Comment thread wpiutil/src/test/java/org/wpilib/util/option/SomeTest.java
@zachwaffle4

Copy link
Copy Markdown
Contributor

Should this PR also switch things currently using java.util.Optional to this new type, or is that intentionally left for a separate PR?

@SamCarlberg

SamCarlberg commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Should this PR also switch things currently using java.util.Optional to this new type, or is that intentionally left for a separate PR?

It's intentionally left for a followup PR

@SamCarlberg SamCarlberg changed the title Add an Option type to wpiutil [wpiutil java] Add an Option type Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: wpiutil Utility library type: testing Related to testing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wpiutil] Add Java algebraic data types

3 participants