safe is a small Java library designed to provide a more efficient and concise way to access references. It offers a simple and expressive syntax to handle nullable or optional references in a more streamlined manner, reducing the need for boilerplate code and potential null pointer exceptions.
- Provides a fluent API for accessing references in a safe and efficient way.
- Simplifies handling of nullable or optional references.
- Reduces boilerplate code and potential null pointer exceptions.
- Supports Java 20 (enabled preview) or higher.
import dev.orhantugrul.safe.Ref;
import dev.orhantugrul.safe.Maybe.Just;
import dev.orhantugrul.safe.Maybe.Nothing;
class Main {
public static void main(final String[] args) {
final var happyReference = switch (Ref.from(null)) {
case Just(final var value) -> value;
case Nothing() -> throw new AssertionError("There is no value :/");
};
}
}
Contributions to safe are welcome! If you would like to contribute, please follow these steps:
- Fork the repository and clone it to your local machine.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them, following the conventional commit message format.
- Push your changes to your forked repository.
- Submit a pull request to the
main
branch of the original repository.
Please ensure that your code adheres to the existing coding style and that you have added appropriate tests for your changes.
safe is open-source software licensed under the MIT License. Feel free to use, modify, and distribute it as outlined in the license.