A lightweight, zero-dependency Result pattern implementation for Unity projects. Handle operation outcomes cleanly without exceptions.
- ✨ Type-Safe Error Handling - Handle failures without throwing exceptions.
- 🧩 Composable - Chain operations with functional programming patterns.
- ⚡ High Performance - Zero-allocation patterns and lightweight structs.
- 🧵 Thread-Safe - Immutable types safe for concurrent use.
- 📘 Well-Documented - Comprehensive XML documentation and examples.
- Open the Unity Package Manager
- Click the '+' button in the top-left corner
- Select "Add package from git URL"
- Enter:
https://github.com/ahmedkamalio/ResultObjectForUnity.git?path=/Assets/ResultObject
// Success cases
Result<int> success = Result.Success(42);
Result<string> failure = Result.Failure<string>("Not found", "404");
// Handle results
string message = result.Match(
success: value => $"Got {value}",
failure: error => $"Error: {error}"
);
// Chain operations
Result<User> result = GetUser(id)
.Bind(user => UpdateUser(user))
.Bind(user => SaveUser(user));
// Void operations with Unit
Result<Unit> SaveChanges()
{
if (error)
return Result.Unit(new ResultError("Save failed"));
return Result.Unit();
}
// Safe exception handling
Result<int> result = Result.Try(() =>
int.Parse(input)
);
For complete documentation, see:
Contributions are welcome! Please read our Contributing Guidelines before submitting PRs.
This validation library is licensed under the MIT License - see the LICENSE file for details.