Exploring the concept of "monads" implementing mechanisms to deal with side effects as values. My original goal were to make the AsyncRepositoryReturn type to serve as the return type for my persistency repositories. To do so I mainly needed to deal with the following possible side effects that already are addressed by some monads:
- Absense of value (? type anotation: nullability);
- Assyncronicity (Promises and async/await);
- Multiplicity (Array);
- Fallibility (Error values);
If I understand anything about monads it is that it's composition is tricky. So this repo is my attempt at implementing the following types:
Maybe: Encapsulates the possible absense of value. An optional value. There are someSomeorNone;Either: Encapsulates a value of one of two possible types,LeftorRight.Result: Encapsulates aSuccessvalue or aFailure(error).RepositoryReturn: Encapsulates an array, an error or none.Success<Array>,FailureorNone;AsyncRepositoryReturn: Encapsulates aPromiseof an array, an error or none (Promise<RepositoryReturn>).