error_or 0.0.1
error_or: ^0.0.1 copied to clipboard
A simple class for returning a value or an error
example/error_or_example.dart
import 'dart:math';
import 'package:error_or/error_or.dart';
Future<ErrorOr<String>> getValue() async {
await Future.delayed(Duration(seconds: 1));
if (Random().nextBool() == false) {
return ErrorOr.error(Exception('Error'));
}
return ErrorOr.value('Success');
}
void main() async {
final errorOr = await getValue();
if (errorOr.hasError) {
print(errorOr.error);
return;
}
print(errorOr.value);
}