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
-
bimap<
L2, R2> (L2 ifLeft(L left), R2 ifRight(R right)) → Either< L2, R2> -
Applies
ifLeftorifRightand returns a new Either with mapped values.override -
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 -
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
-
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
-
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 -
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
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override