Either<L, R> class sealed

A disjoint union with a value of either type L or type R.

Also see https://en.wikipedia.org/wiki/Either_type.

Annotations
  • @immutable

Constructors

Either.either(Map0<L?> leftProvider, Map0<R?> rightProvider)
Creates a left-biased Either. This means, if the leftProvider returns a non-null value create a left-sided Either. Alternatively, if the rightProvider returns a non-null value, create a right-sided Either. Otherwise, if both providers return a null-value, throw a StateError.
factory
Either.iff(bool condition, Map0<L> leftProvider, Map0<R> rightProvider)
Creates an left-sided Either from the leftProvider, if condition is true. Otherwise, create a right-sided Either from the rightProvider.
factory
Either.left(L value)
Creates an Either with the left value populated.
const
factory
Either.right(R value)
Creates an Either with the right value populated.
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isLeft bool
Returns true, if this is a left value.
no setter
isRight bool
Returns true, if this has a right value.
no setter
leftOptional Optional<L>
Returns the left value as an Optional.
no setter
leftValue → L
Returns the left value, if absent throws a StateError.
no setter
rightOptional Optional<R>
Returns the right value as an Optional.
no setter
rightValue → R
Returns the right value, if absent throws a StateError.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tuple → (L?, R?)
Returns a tuple with either the left or right value defined.
no setter
value → dynamic
Returns a dynamically typed value of this object, either the leftValue or the rightValue.
no setter

Methods

flatMap<L2, R2>(Map1<L, Either<L2, R2>> leftFunction, Map1<R, Either<L2, R2>> rightFunction) Either<L2, R2>
Returns a new Either created by the either-returning transformation leftFunction or rightFunction.
flatMapLeft<L2>(Map1<L, Either<L2, R>> leftFunction) Either<L2, R>
Returns a new Either from the either-returning transformation leftFunction, otherwise returns the wrapped right value.
flatMapRight<R2>(Map1<R, Either<L, R2>> rightFunction) Either<L, R2>
Returns a new Either from the either-returning transformation rightFunction, otherwise returns the wrapped left value.
fold<T>(Map1<L, T> leftFunction, Map1<R, T> rightFunction) → T
Returns the appropriate transformation to type T.
map<L2, R2>(Map1<L, L2> leftFunction, Map1<R, R2> rightFunction) Either<L2, R2>
Transforms the left value with leftFunction or the right value with rightFunction. The resulting Either contains the transformed value of the corresponding function.
mapLeft<L2>(Map1<L, L2> leftFunction) Either<L2, R>
Transforms the left value with leftFunction. If applicable, the resulting Either contains the transformed left value.
mapRight<R2>(Map1<R, R2> rightFunction) Either<L, R2>
Transforms the right value with rightFunction. If applicable, the resulting Either contains the transformed right value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
swap() Either<R, L>
Returns a new Either with the left and right value switched.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited