A Maybe type for use in Unity.
A Maybe, or Option Type, provides a generic mechanism for working with a return (or field etc.) that may or may not have a value in it.
- It's a struct, so avoids the potential for many tiny allocations that may occur if using a nullable int.
- Includes a number of extension methods for Linq, allowing for functional and Railway style programming.
- Tested against Unity specifics. So it handles things like GetComponent returning an object that says it's null but isn't
is null. - A git url package with source code, so no random dlls cluttering up your unity project or repo.
If you aren't in Unity or you don't need Unity specifics accounted for, you should go use language-ext, or CSharpFunctionalExtensions, or perhaps Optional.
The required library is distributed as a git package (How to install package from git URL)
https://github.com/ActuatorDigital/Maybe.git?path=Packages/Maybe
go.GetComponentOrNone<Rigidbody>()
.MatchSome(x => x.AddForce(Vector3.up));The Tests in the package folder are also a great way to see what the package provides.