Right<A, B> final
final class Right<A, B> extends Either<A, B>One of two possible instances of Either, generally used to indicate a successful value.
Inheritance
Object → Either<A, B> → Right<A, B>
Available Extensions
Constructors
Right() const
const Right(B b)Implementation
const Right(this.b);Properties
b final
final B bImplementation
final B b;hashCode no setter inherited
int get hashCodeThe 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
bool get isLeftReturns true if this is a Left, otherwise false is returned.
Implementation
@override
bool get isLeft => false;isRight no setter inherited
bool get isRightReturns true if this is a Right, otherwise false is returned.
Inherited from Either.
Implementation
bool get isRight => !isLeft;runtimeType no setter inherited
Type get runtimeTypeA 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
Either<C, D> bimap<C, D>(C Function(A) fa, D Function(B) fb)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
bool contains(B elem)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
Either<A, B> ensure(bool Function(B) p, A Function() onFailure)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
bool exists(bool Function(B) p)Inherited from Either.
Implementation
bool exists(Function1<B, bool> p) => foldLeft(false, (acc, elem) => acc || p(elem));filterOrElse() inherited
Either<A, B> filterOrElse(bool Function(B) p, A Function() zero)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 is 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) => f(b);fold() override
C fold<C>(C Function(A) fa, C Function(B) fb)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) => fb(b);foldLeft() inherited
R2 foldLeft<R2>(R2 init, R2 Function(R2, B) op)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
R2 foldRight<R2>(R2 init, R2 Function(B, R2) op)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
bool forall(bool Function(B) p)Inherited from Either.
Implementation
bool forall(Function1<B, bool> p) => foldLeft(true, (acc, elem) => acc && p(elem));foreach() inherited
void foreach<U>(U Function(B) f)Applies side effect f if this is a Right.
Inherited from Either.
Implementation
void foreach<U>(Function1<B, U> f) => fold((_) {}, f);getOrElse() inherited
B getOrElse(B Function() orElse)Returns thes 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
Either<C, B> leftMap<C>(C Function(A) f)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
Either<A, C> map<C>(C Function(B) f)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) => Right(f(b));noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)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
Either<B, A> swap()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
IList<B> toIList()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
Option<B> toOption()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
String toString()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
Validated<A, B> toValidated()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
Either<E, Record> ensureN(bool Function(T1, T2) p, E Function() onFailure)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
Either<E, Record> ensureN(
bool Function(T1, T2, T3, T4, T5) p,
E Function() onFailure,
)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
Either<E, Record> ensureN(
bool Function(T1, T2, T3, T4) p,
E Function() onFailure,
)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
Either<E, Record> ensureN(bool Function(T1, T2, T3) p, E Function() onFailure)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
Either<E, Record> filterOrElseN(bool Function(T1, T2, T3) p, E Function() zero)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
Either<E, Record> filterOrElseN(
bool Function(T1, T2, T3, T4, T5) p,
E Function() zero,
)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
Either<E, Record> filterOrElseN(
bool Function(T1, T2, T3, T4) p,
E Function() zero,
)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
Either<E, Record> filterOrElseN(bool Function(T1, T2) p, E Function() zero)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
Either<A, B> flatten()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
T6 foldN<T6>(T6 Function(E) f, T6 Function(T1, T2, T3, T4, T5) g)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
T4 foldN<T4>(T4 Function(E) f, T4 Function(T1, T2, T3) g)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
T3 foldN<T3>(T3 Function(E) f, T3 Function(T1, T2) g)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
T5 foldN<T5>(T5 Function(E) f, T5 Function(T1, T2, T3, T4) g)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
void foreachN(void Function(T1, T2) f)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
void foreachN(void Function(T1, T2, T3) f)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
void foreachN(void Function(T1, T2, T3, T4) f)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
void foreachN(void Function(T1, T2, T3, T4, T5) f)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
Either<E, T3> mapN<T3>(T3 Function(T1, T2) f)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
Either<E, T6> mapN<T6>(T6 Function(T1, T2, T3, T4, T5) f)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
Either<E, T4> mapN<T4>(T4 Function(T1, T2, T3) f)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
Either<E, T5> mapN<T5>(T5 Function(T1, T2, T3, T4) f)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
bool operator ==(Object other)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);