Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be πŸ“–

GDScript Optional

An asset by blumm96
The page banner background of a mountain and forest
GDScript Optional hero image

Quick Information

0 ratings
GDScript Optional icon image
blumm96
GDScript Optional

A Java-style Optional<T> implementation for Godot Engine (GDScript). Helps you safely wrap nullable values and avoid unsafe null checks.

Supported Engine Version
4.4
Version String
1.0.2
License Version
MIT
Support Level
community
Modified Date
17 days ago
Git URL
Issue URL

License

This project is licensed under the MIT License.

Optional for Godot (GDScript)

A Java-style Optional<T> 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

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.

A Java-style Optional implementation for Godot Engine (GDScript). Helps you safely wrap nullable values and avoid unsafe null checks.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
GDScript Optional icon image
blumm96
GDScript Optional

A Java-style Optional<T> implementation for Godot Engine (GDScript). Helps you safely wrap nullable values and avoid unsafe null checks.

Supported Engine Version
4.4
Version String
1.0.2
License Version
MIT
Support Level
community
Modified Date
17 days ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers