mirror of
https://github.com/Uuttssaavv/flutter-clean-architecture-riverpod.git
synced 2025-08-15 02:26:14 +08:00
28 lines
627 B
Dart
28 lines
627 B
Dart
sealed class Either<L, R> {
|
|
const Either();
|
|
factory Either.left(L l) => Left(l);
|
|
factory Either.right(R r) => Right(r);
|
|
|
|
T fold<T>(T Function(L) left, T Function(R) right) => switch (this) {
|
|
Left(:final value) => left(value),
|
|
Right(:final value) => right(value),
|
|
};
|
|
bool isLeft() => switch (this) {
|
|
Left() => true,
|
|
Right() => false,
|
|
};
|
|
bool isRight() => !isLeft();
|
|
}
|
|
|
|
class Left<L, R> extends Either<L, R> {
|
|
final L _l;
|
|
const Left(this._l);
|
|
L get value => _l;
|
|
}
|
|
|
|
class Right<L, R> extends Either<L, R> {
|
|
final R _r;
|
|
const Right(this._r);
|
|
R get value => _r;
|
|
}
|