
B
Publisher
blumm96
GDScript Optional
Tools
Optional GDScript Nullable Safety Java Programming Development Value
A Java-style Optional
This plugin has been mirrored from the Godot Asset Library.
The plugin author is in no way affiliated with Gadget.
If you are the author of this plugin and would like this mirror removed, please contact support@gadgetgodot.com.
License
This project is licensed under the MIT 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 valueOptional.of_nullable(value)
– wraps value, allows nullOptional.empty()
– explicitly empty optionalunwrap()
– get the value or assertunwrap_or(default)
– get value or fallbackmap(func)
– transform value if presentflat_map(func)
– transform with function returning Optional
Example
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
- Copy the
addons/optional/
folder into your project. - Enable the plugin in Project Settings → Plugins.
- Use
Optional
in your scripts.