elegant 2.0.0
elegant: ^2.0.0 copied to clipboard
A collection of utility functions and classes.
A utility package containing all the little functions and classes I find myself reusing frequently. This will be expanded, documented and fit for general public use eventually, when I find the time.
Result #
Result<T, E> is a Rust-inspired sealed type for computations that either
succeed with a value or fail with an error:
Result<int, String> parseCount(String source) {
final value = int.tryParse(source);
return value == null
? Result.error('Not a number')
: Result.ok(value);
}
final message = switch (parseCount('42')) {
Ok(:final value) => 'Parsed $value',
Err(:final error) => 'Failed: $error',
};
Results support map, andThen, mapError, fold, unwrap,
unwrapError, unwrapOrElse, and toNullable.
The unnamed Result constructor was removed in 2.0. Existing
Result.ok(...) and Result.error(...) calls remain supported. The old
nullable getters and transform methods are deprecated in favor of pattern
matching and the new operations.