UniTask extensions for CSharpFunctionalExtensions
There are several ways to install this library into our project:
- OpenUPM: After installing openupm-cli, run the following command:
openupm add ext.csharpfunctionalextensions.unitask
- Unity Package Manager (UPM): Add the following line to Packages/manifest.json:
"ext.csharpfunctionalextensions.unitask": "https://github.com/Razenpok/CSharpFunctionalExtensions.UniTask.git?path=src/CSharpFunctionalExtensions.UniTask",
- Clone source code: Clone or download this repository and put the src/CSharpFunctionalExtensions.UniTask folder somewhere in your Unity project
You will also need to obtain a compatible version of CSharpFunctionalExtensions library (major version must match with CSharpFunctionalExtensions.UniTask):
- UnityNuGet registry: you can install the library directly via OpenUPM using the following comand:
openupm add org.nuget.csharpfunctionalextensions
- NuGetForUnity plugin
- NuGet: Download a .nupkg file from NuGet registry, change the file extension to .zip, unzip it, find the .dll file in lib/netstandard2.0 folder
You can find the extensive set of usage examples in the CSharpFunctionalExtensions repository
Here is a short primer if you are not familiar with this library
Result<CustomerName> name = CustomerName.Create(model.Name);
Result<Email> email = Email.Create(model.PrimaryEmail);
Result result = Result.Combine(name, email);
if (result.IsFailure)
return Error(result.Error);
var customer = new Customer(name.Value, email.Value);
Maybe<Customer> customerOrNothing = _customerRepository.GetById(id);
if (customerOrNothing.HasNoValue)
return Error("Customer with such Id is not found: " + id);
return _customerRepository.GetById(id)
.ToResult("Customer with such Id is not found: " + id)
.Ensure(customer => customer.CanBePromoted(), "The customer has the highest status possible")
.Tap(customer => customer.Promote())
.Tap(customer => _emailGateway.SendPromotionNotification(customer.PrimaryEmail, customer.Status))
.Finally(result => result.IsSuccess ? Ok() : Error(result.Error));