https://github.com/blumm96/gdscript-optional
A Java-style Optional<T> implementation for Godot Engine (GDScript).
https://github.com/blumm96/gdscript-optional
gdscript godot optional plugin
Last synced: 7 months ago
JSON representation
A Java-style Optional<T> implementation for Godot Engine (GDScript).
- Host: GitHub
- URL: https://github.com/blumm96/gdscript-optional
- Owner: blumm96
- License: mit
- Created: 2025-06-02T19:27:16.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-06-02T21:18:04.000Z (8 months ago)
- Last Synced: 2025-06-29T10:39:40.611Z (8 months ago)
- Topics: gdscript, godot, optional, plugin
- Language: GDScript
- Homepage:
- Size: 36.1 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## License
This project is licensed under the [MIT License](LICENSE).
# Optional for Godot (GDScript)
A Java-style `Optional` implementation for Godot Engine (GDScript). Helps you safely wrap nullable values and avoid unsafe null checks.
## Features
- `Optional.of(value)` – requires a non-null value
- `Optional.of_nullable(value)` – wraps value, allows null
- `Optional.empty()` – explicitly empty optional
- `unwrap()` – get the value or assert
- `unwrap_or(default)` – get value or fallback
- `map(func)` – transform value if present
- `flat_map(func)` – transform with function returning Optional
## Example
```gdscript
var maybe_number = Optional.of_nullable(42)
maybe_number.if_present(func(v): print("Value is: ", v))
var result = maybe_number.map(func(v): return v * 2).unwrap_or(0)
print(result) # -> 84
```
## Installation
1. Copy the `addons/optional/` folder into your project.
2. Enable the plugin in Project Settings → Plugins.
3. Use `Optional` in your scripts.