Left<A, B> final
One of two possible instances of Either, generally used to indicate an error, or failure of some kind.
Inheritance
Object → Either<A, B> → Left<A, B>
Available Extensions
Constructors
Left() const
Implementation
const Left(this.a);Properties
a final
Implementation
final A a;hashCode no setter inherited
The hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Either.
Implementation
@override
int get hashCode => fold((a) => a.hashCode, (b) => b.hashCode);isLeft no setter override
Returns true if this is a Left, otherwise false is returned.
Implementation
@override
bool get isLeft => true;isRight no setter inherited
Returns true if this is a Right, otherwise false is returned.
Inherited from Either.
Implementation
bool get isRight => !isLeft;leftOption no setter inherited
Returns the Left value wrapped in a Some, or None if this is a Right.
Inherited from Either.
Implementation
Option<A> get leftOption => fold(Some.new, (_) => none<A>());rightOption no setter inherited
Returns the Right value wrapped in a Some, or None if this is a Left.
Inherited from Either.
Implementation
Option<B> get rightOption => fold((_) => none<B>(), Some.new);runtimeType no setter inherited
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;Methods
ap() inherited
Applies the value of f to the value of this instance if both are a Right. If either this or f is a Left, that value is returned, in that order.
Inherited from Either.
Implementation
@override
Either<A, C> ap<C>(Either<A, Function1<B, C>> f) =>
fold((a) => left<A, C>(a), (b) => f.fold((a) => left<A, C>(a), (f) => right(f(b))));bimap() inherited
Applies the appropriate function fa or fb to the value of this instance depending on if this is a Left or Right.
Inherited from Either.
Implementation
Either<C, D> bimap<C, D>(Function1<A, C> fa, Function1<B, D> fb) =>
fold((a) => left<C, D>(fa(a)), (b) => right(fb(b)));contains() inherited
Returns true if this instance is a Right and the value equals elem.
Inherited from Either.
Implementation
bool contains(B elem) => fold((_) => false, (b) => elem == b);ensure() inherited
Checks if the value of this Right satisfies the given predicate p. If this is a Left, then this is returned. If this is a Right but the value doesn't pass the test, the result of evaluating onFailure is returned.
Inherited from Either.
Implementation
Either<A, B> ensure(Function1<B, bool> p, Function0<A> onFailure) =>
fold((_) => this, (b) => p(b) ? this : left(onFailure()));exists() inherited
Inherited from Either.
Implementation
bool exists(Function1<B, bool> p) => foldLeft(false, (acc, elem) => acc || p(elem));filterOrElse() inherited
Checks if the value of this Right satisfies the given predicate p. If this is a Left or if the Right value does not satisfy p, then the value is replaced by the result of evaluating zero.
Inherited from Either.
Implementation
Either<A, B> filterOrElse(Function1<B, bool> p, Function0<A> zero) =>
fold((_) => left<A, B>(zero()), (b) => p(b) ? this : left(zero()));flatMap() override
Applies f to this value if this is a Right. If this is a Left, then the original value is returned.
Implementation
@override
Either<A, C> flatMap<C>(Function1<B, Either<A, C>> f) => Either.left<A, C>(a);fold() override
Applies fa if this is a Left, or fb if this is a Right.
Implementation
@override
C fold<C>(Function1<A, C> fa, Function1<B, C> fb) => fa(a);foldLeft() inherited
Applies op to init and this value if this is a Right. If this is a Left, init is returned.
Inherited from Either.
Implementation
R2 foldLeft<R2>(R2 init, Function2<R2, B, R2> op) => fold((_) => init, (r) => op(init, r));foldRight() inherited
Applies op to this value and init if this is a Right. If this is a Left, init is returned.
Inherited from Either.
Implementation
R2 foldRight<R2>(R2 init, Function2<B, R2, R2> op) => fold((_) => init, (r) => op(r, init));forall() inherited
Inherited from Either.
Implementation
bool forall(Function1<B, bool> p) => foldLeft(true, (acc, elem) => acc && p(elem));foreach() inherited
Applies side effect f if this is a Right.
Inherited from Either.
Implementation
void foreach<U>(Function1<B, U> f) => fold((_) {}, f);getOrElse() inherited
Returns the value if this is a Right, otherwise, the result of evaluating orElse is returned.
Inherited from Either.
Implementation
B getOrElse(Function0<B> orElse) => fold((_) => orElse(), identity);leftMap() inherited
Returns a new Either by applying f to the value of this instance if it is a Left.
Inherited from Either.
Implementation
Either<C, B> leftMap<C>(Function1<A, C> f) =>
fold((a) => left<C, B>(f(a)), (b) => right<C, B>(b));map() override
Returns a new Either by applying f to the value of this instance if it is a Right.
Implementation
@override
Either<A, C> map<C>(Function1<B, C> f) => Either.left<A, C>(a);noSuchMethod() inherited
Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);orElse() inherited
If this instance is a Right, this is returned. Otherwise, the result of evaluating orElse is returned.
Inherited from Either.
Implementation
Either<A, B> orElse(Function0<Either<A, B>> or) => fold((a) => or(), (b) => this);product() inherited
Tuples the values of this Either and other if both are instances of Right. Otherwise, the first Left value is returned, this or other in that order.
Inherited from Either.
Implementation
Either<A, (B, C)> product<C>(Either<A, C> other) => (this, other).tupled;swap() inherited
Returns a new Either where the left and right types are swapped.
Inherited from Either.
Implementation
Either<B, A> swap() => fold((a) => right<B, A>(a), (b) => left(b));toIList() inherited
Converts this Either to an IList with one element if this instance is a Right or an empty IList if this is a Left.
Inherited from Either.
Implementation
IList<B> toIList() => fold((_) => nil<B>(), (b) => IList.fromDart([b]));toOption() inherited
Converts this Either to an Option. If this instance is a Right, the value will be returned as a Some. If this instance is a Left, None will be returned.
Inherited from Either.
Implementation
Option<B> toOption() => fold((_) => none<B>(), Some.new);toString() inherited
A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Inherited from Either.
Implementation
@override
String toString() => fold((a) => 'Left($a)', (b) => 'Right($b)');toValidated() inherited
Converts this Either to a Validated, either an Invalid or Valid depending on whether this instance is a Left or Right respectively.
Inherited from Either.
Implementation
Validated<A, B> toValidated() => fold((a) => a.invalid(), (b) => b.valid());Extension Methods
ensureN() extension
Available on Either<A, B>, provided by the EitherTuple2Ops<E, T1, T2> extension
Implementation
Either<E, (T1, T2)> ensureN(
Function2<T1, T2, bool> p,
Function0<E> onFailure,
) => ensure(p.tupled, onFailure);ensureN() extension
Available on Either<A, B>, provided by the EitherTuple5Ops<E, T1, T2, T3, T4, T5> extension
Implementation
Either<E, (T1, T2, T3, T4, T5)> ensureN(
Function5<T1, T2, T3, T4, T5, bool> p,
Function0<E> onFailure,
) => ensure(p.tupled, onFailure);ensureN() extension
Available on Either<A, B>, provided by the EitherTuple4Ops<E, T1, T2, T3, T4> extension
Implementation
Either<E, (T1, T2, T3, T4)> ensureN(
Function4<T1, T2, T3, T4, bool> p,
Function0<E> onFailure,
) => ensure(p.tupled, onFailure);ensureN() extension
Available on Either<A, B>, provided by the EitherTuple3Ops<E, T1, T2, T3> extension
Implementation
Either<E, (T1, T2, T3)> ensureN(
Function3<T1, T2, T3, bool> p,
Function0<E> onFailure,
) => ensure(p.tupled, onFailure);filterOrElseN() extension
Available on Either<A, B>, provided by the EitherTuple3Ops<E, T1, T2, T3> extension
Implementation
Either<E, (T1, T2, T3)> filterOrElseN(
Function3<T1, T2, T3, bool> p,
Function0<E> zero,
) => filterOrElse(p.tupled, zero);filterOrElseN() extension
Available on Either<A, B>, provided by the EitherTuple5Ops<E, T1, T2, T3, T4, T5> extension
Implementation
Either<E, (T1, T2, T3, T4, T5)> filterOrElseN(
Function5<T1, T2, T3, T4, T5, bool> p,
Function0<E> zero,
) => filterOrElse(p.tupled, zero);filterOrElseN() extension
Available on Either<A, B>, provided by the EitherTuple4Ops<E, T1, T2, T3, T4> extension
Implementation
Either<E, (T1, T2, T3, T4)> filterOrElseN(
Function4<T1, T2, T3, T4, bool> p,
Function0<E> zero,
) => filterOrElse(p.tupled, zero);filterOrElseN() extension
Available on Either<A, B>, provided by the EitherTuple2Ops<E, T1, T2> extension
Implementation
Either<E, (T1, T2)> filterOrElseN(
Function2<T1, T2, bool> p,
Function0<E> zero,
) => filterOrElse(p.tupled, zero);flatMapN() extension
Available on Either<A, B>, provided by the EitherTuple4Ops<E, T1, T2, T3, T4> extension
Implementation
Either<E, T5> flatMapN<T5>(Function4<T1, T2, T3, T4, Either<E, T5>> f) => flatMap(f.tupled);flatMapN() extension
Available on Either<A, B>, provided by the EitherTuple3Ops<E, T1, T2, T3> extension
Implementation
Either<E, T4> flatMapN<T4>(Function3<T1, T2, T3, Either<E, T4>> f) => flatMap(f.tupled);flatMapN() extension
Available on Either<A, B>, provided by the EitherTuple2Ops<E, T1, T2> extension
Implementation
Either<E, T3> flatMapN<T3>(Function2<T1, T2, Either<E, T3>> f) => flatMap(f.tupled);flatMapN() extension
Available on Either<A, B>, provided by the EitherTuple5Ops<E, T1, T2, T3, T4, T5> extension
Implementation
Either<E, T6> flatMapN<T6>(Function5<T1, T2, T3, T4, T5, Either<E, T6>> f) => flatMap(f.tupled);flatten() extension
Extracts the nested Either via fold.
Available on Either<A, B>, provided by the EitherNestedOps<A, B> extension
Implementation
Either<A, B> flatten() => fold((a) => Either.left<A, B>(a), identity);foldN() extension
Available on Either<A, B>, provided by the EitherTuple5Ops<E, T1, T2, T3, T4, T5> extension
Implementation
T6 foldN<T6>(
Function1<E, T6> f,
Function5<T1, T2, T3, T4, T5, T6> g,
) => fold(f, g.tupled);foldN() extension
Available on Either<A, B>, provided by the EitherTuple3Ops<E, T1, T2, T3> extension
Implementation
T4 foldN<T4>(
Function1<E, T4> f,
Function3<T1, T2, T3, T4> g,
) => fold(f, g.tupled);foldN() extension
Available on Either<A, B>, provided by the EitherTuple2Ops<E, T1, T2> extension
Implementation
T3 foldN<T3>(
Function1<E, T3> f,
Function2<T1, T2, T3> g,
) => fold(f, g.tupled);foldN() extension
Available on Either<A, B>, provided by the EitherTuple4Ops<E, T1, T2, T3, T4> extension
Implementation
T5 foldN<T5>(
Function1<E, T5> f,
Function4<T1, T2, T3, T4, T5> g,
) => fold(f, g.tupled);foreachN() extension
Available on Either<A, B>, provided by the EitherTuple2Ops<E, T1, T2> extension
Implementation
void foreachN(Function2<T1, T2, void> f) => foreach(f.tupled);foreachN() extension
Available on Either<A, B>, provided by the EitherTuple3Ops<E, T1, T2, T3> extension
Implementation
void foreachN(Function3<T1, T2, T3, void> f) => foreach(f.tupled);foreachN() extension
Available on Either<A, B>, provided by the EitherTuple4Ops<E, T1, T2, T3, T4> extension
Implementation
void foreachN(Function4<T1, T2, T3, T4, void> f) => foreach(f.tupled);foreachN() extension
Available on Either<A, B>, provided by the EitherTuple5Ops<E, T1, T2, T3, T4, T5> extension
Implementation
void foreachN(Function5<T1, T2, T3, T4, T5, void> f) => foreach(f.tupled);mapN() extension
Available on Either<A, B>, provided by the EitherTuple2Ops<E, T1, T2> extension
Implementation
Either<E, T3> mapN<T3>(Function2<T1, T2, T3> f) => map(f.tupled);mapN() extension
Available on Either<A, B>, provided by the EitherTuple5Ops<E, T1, T2, T3, T4, T5> extension
Implementation
Either<E, T6> mapN<T6>(Function5<T1, T2, T3, T4, T5, T6> f) => map(f.tupled);mapN() extension
Available on Either<A, B>, provided by the EitherTuple3Ops<E, T1, T2, T3> extension
Implementation
Either<E, T4> mapN<T4>(Function3<T1, T2, T3, T4> f) => map(f.tupled);mapN() extension
Available on Either<A, B>, provided by the EitherTuple4Ops<E, T1, T2, T3, T4> extension
Implementation
Either<E, T5> mapN<T5>(Function4<T1, T2, T3, T4, T5> f) => map(f.tupled);Operators
operator ==() inherited
The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Either.
Implementation
@override
bool operator ==(Object other) =>
fold((a) => other is Left && a == other.a, (b) => other is Right && b == other.b);