result_monad 4.0.0
result_monad: ^4.0.0 copied to clipboard
A Dart implementation of the Result Monad which allows for more expressive result generation and processing without using exceptions.
4.0.0 #
- Change Ok class's field to be "value" which overrides base-class value property. Since the 3.x version has been pulled and this technically changes the field of Ok, even though it wouldn't normally be used. This technically bumps the version number to 4.0.0
3.0.2 #
- Fix having version in CHANGELOG align with pub.dev version to get perfect score.
3.0.1 #
- Update README to new syntax
3.0.0 #
NOTE 1: This release has some breaking changes and an increased minimum SDK version bump from the 2.3.2 release.
NOTE 2: Many thanks to the contributions to the ADT-related updates and StackTrace functionality updates contributed by Daniel Gomez Rico (danielgomezrico@gmail.com). Some of the changes were taken through Pull Request acceptance while others were back-ported with some changes from his fork of this project
- Underlying architecture now
uses Algebraic Data Type (ADT)
functionality introduced with class modifiers and patterns
in Dart 3.0.0 in May 2023.
- This made the syntax for creating Results more compact (and preferred way to create Results now):
Result.ok('Good')=>Ok('Good)Result.error('Bad')=>Error('Bad')
- This also makes it so you can use switch statements, if statements, et cetera on return values directly, although somewhat redudant with the various aggregation operations in the library.
- Example:
- This made the syntax for creating Results more compact (and preferred way to create Results now):
// The below fold function...
final value = invert(2).fold(
onSuccess: (v) => v,
onError: (e, trace) => e,
);
// Can be expressed:
final value = switch (invert(2)) {
Ok o => o.value,
Error e => e.cause,
Result _ => throw UnimplementedError(), // there since Result isn't sealed
};
- Breaking change: Minimum Dart version bumped up from 2.14.4 to 3.0.0
- Breaking change: Added Stack Trace following functionality so can get insight into where the error occurred in a
chain of calls. This changed the function signatures on the following method to add access to stack traces when
processing errors
- On
Result:fold,match,withError,withErrorAsync - On
FutureResult:fold,match,withError,withErrorAsync
- On
- Add optional
StackTraceparameter onErrorresult creationError('Bad', StackTrace.current) Resulthas astackTraceproperty that can be called if and only if the type is an Error. Result can be null.ResulthasasOkandasErrorproperties for casting to specific type. This will throw an Exception if is against the underlying type for that instance.- Thanks to GitLab User DoodleSchrank for adding additional pass-through methods on
FutureResultto their correspondingResultmethods:getErrorOrElse,getValueOrElse,getErrorOrElseAsync,getValueOrElseAsync - Updated examples and documentation to reflect the syntax updates.
2.3.2 #
- Tweak to documentation headers to avoid lint error
2.3.1 #
- Tweak to README to include
withErrorandwithErrorAsync
2.3.0 #
- Examples and documentation updates for the new syntax.
- Add to
FutureResult:andThen,errorCast,mapError,mapValue,withResult,withError,match,fold - Add
withErrorto Result andwithErrorandwithErrorAsynctoFutureResult
2.1.0 #
- Add pass through methods
withResultandwithResultAsyncon Result and Future extension method
2.0.2 #
- Add exception catching on
addThenandaddThenSuccessand FutureResult extension methods.
2.0.1 #
- Tweaks to the README only.
2.0.0 #
- Allow nullable types for success and failure types
- Add
andThenSuccessandandThenSuccessAsyncmethods for allowing returning results without explicitResult.okwrapping to allow more concise syntax - Add extension methods on
FutureResultto make async chaining syntax much more concise - Add
errorCastmethod for when need to pass up an error Result with the same error type with different success type.
1.0.2 #
- Tweaks to API documentation
- Added temp file "intermediate" level example and added it to
example.mdas well
1.0.1 #
- Added an
example.mdfile for pub.dev.
1.0.0 #
- Initial version.