focus-flow/packages/scheduler_persistence/lib/persistence/results/either.dart

24 lines
779 B
Dart

part of '../../persistence.dart';
/// Minimal Either type for expected repository success/failure paths.
sealed class Either<L, R> {
const Either();
/// Whether this value is a left/failure value.
bool get isLeft => this is Left<L, R>;
/// Whether this value is a right/success value.
bool get isRight => this is Right<L, R>;
/// Return the left value or throw when this is right.
L get left => switch (this) {
Left<L, R>(:final value) => value,
Right<L, R>() => throw StateError('Either does not contain left.'),
};
/// Return the right value or throw when this is left.
R get right => switch (this) {
Left<L, R>() => throw StateError('Either does not contain right.'),
Right<L, R>(:final value) => value,
};
}