Okerr is a Dart package for Result type of Rust.
The majority of methods in std::result of Rust has been implemented. The criteria for implementation are:
- The method is not in the nightly-only experimental API. For example, is_ok_and is not implemented in this package.
- The methods that deal with ownership and borrowing do not make sense in the context of Dart. Thus,
as_deref_mut, etc. are not implemented.
- The methods that deal with iteration are not implemented such as
- Unsafe methods are not implemented.
match method is implemented to mimic the pattern matching with
Results in Rust.
Check the API documentation in order to see all the implemented methods.
match is a method that mimics the pattern matching with
Results in Rust. See the example:
final result1 = Ok(0); final value1 = result1.match( ok: (value) => value == 0, err: (error) => false, ); // value1 is `true` final result2 = Err(0); final value2 = result2.match( ok: (value) => value == 0, err: (error) => false, ); // value2 is `false`
result package is another one targeting the same thing, but it's not been updated for years now whereas Dart has changed a lot. It can be error-prone to use.
dartz is another alternative. It is essentially a functional programming library and comes with many things such as immutable persistent collections, type class instances etc. Its Either class holds similarity to