Left<L, R> class
Represents the failure or error side of an Either.
A Left<L, R> contains a value of type L, typically used to represent
an error or exceptional case. This is returned from methods that may fail,
instead of throwing exceptions.
Operations like map and flatMap are no-ops on Left, meaning they
return the same Left unchanged.
Example:
Either<String, int> result = const Left('Something went wrong');
print(result.isLeft()); // true
print(result.isRight()); // false
print(result.getLeft()); // 'Something went wrong'
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → L
-
The encapsulated value, typically representing an error or failure.
final
Methods
-
all(
bool test(R right)) → bool -
Returns
truewhen this is a Left or whentestpasses for the Right value.inherited -
bimap<
L2, R2> (L2 ifLeft(L left), R2 ifRight(R right)) → Either< L2, R2> -
Applies
ifLeftorifRightand returns a new Either with mapped values.override -
contains(
R value) → bool -
Returns
truewhen this is a Right containingvalue.inherited -
exists(
bool test(R right)) → bool -
Returns
truewhen this is a Right andtestpasses.inherited -
flatMap<
R2> (Either< L, R2> f(R right)) → Either<L, R2> -
Applies the function
fto the value contained in Right, if it exists, and returns a new Either containing the result. If this is a Left, it is returned unchanged.override -
flatMapAsync<
R2> (FutureOr< Either< f(R right)) → Future<L, R2> >Either< L, R2> > -
Asynchronously applies
fto the Right value, if present.override -
fold<
B> (B ifLeft(L left), B ifRight(R right)) → B -
Applies one of two functions depending on whether this is a Left or Right.
override
-
foldAsync<
B> (FutureOr< B> ifLeft(L left), FutureOr<B> ifRight(R right)) → Future<B> -
Asynchronously applies one of two functions depending on the side present.
inherited
-
getLeft(
) → L -
Returns the Left value if this is a Left, otherwise throws.
override
-
getOrElse(
R orElse(L left)) → R -
Returns the Right value if this is a Right, otherwise computes a fallback.
inherited
-
getOrNull(
) → R? -
Returns the Right value if this is a Right, otherwise
null.inherited -
getRight(
) → R -
Returns the Right value if this is a Right, otherwise throws.
override
-
isLeft(
) → bool -
Returns
trueif this is a Left.override -
isRight(
) → bool -
Returns
trueif this is a Right.override -
leftOrNull(
) → L? -
Returns the Left value if this is a Left, otherwise
null.override -
map<
R2> (R2 f(R right)) → Either< L, R2> -
Transforms the value contained in Right using the given function
f, returning a new Either with the transformed value.override -
mapAsync<
R2> (FutureOr< R2> f(R right)) → Future<Either< L, R2> > -
Asynchronously transforms the Right value using
f, if present.override -
mapLeft<
L2> (L2 f(L left)) → Either< L2, R> -
Maps the Left value using
f, if present.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rightOrNull(
) → R? -
Returns the Right value if this is a Right, otherwise
null.override -
swap(
) → Either< R, L> -
Swaps the sides of this Either, turning Left into Right and vice versa.
override
-
tap(
void f(R right)) → Either< L, R> -
Runs
fwith the Right value, if present, and returns this Either.inherited -
tapLeft(
void f(L left)) → Either< L, R> -
Runs
fwith the Left value, if present, and returns this Either.inherited -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override