Either<L, R> class sealed

Represents a value that can be either a Left (error) or Right (success).

Either is commonly used in functional programming to handle computations that may fail without throwing exceptions.

Implementers
Available extensions

Properties

hashCode int
The hash code for this object.
no setterinherited
isLeft bool
Returns true if this is a Left
no setter
isRight bool
Returns true if this is a Right
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

filter(bool predicate(R), L orElse()) Either<L, R>

Available on Either<L, R>, provided by the EitherExtensions extension

Filters the right value with a predicate, converting to Left if false
flatMap<R2>(Either<L, R2> f(R)) Either<L, R2>
Flat maps the right value if this is a Right
flatMapLeft<L2>(Either<L2, R> f(L)) Either<L2, R>
Flat maps the left value if this is a Left
fold<T>(T onLeft(L), T onRight(R)) → T
Folds this Either into a single value
getOrElse(R defaultValue) → R
Returns the right value if this is a Right, otherwise returns the default value
getOrElseGet(R defaultValue()) → R
Returns the right value if this is a Right, otherwise computes and returns a default value
map<R2>(R2 f(R)) Either<L, R2>
Maps the right value if this is a Right, otherwise returns this Left unchanged
mapLeft<L2>(L2 f(L)) Either<L2, R>
Maps the left value if this is a Left, otherwise returns this Right unchanged
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
swap() Either<R, L>
Swaps Left and Right
toList() List<R>

Available on Either<L, R>, provided by the EitherExtensions extension

Converts this Either to a list, containing the right value or empty for Left
toNullable() → R?

Available on Either<L, R>, provided by the EitherExtensions extension

Converts this Either to a nullable value, returning null for Left
toString() String
A string representation of this object.
override

Operators

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

Static Methods

left<L, R>(L value) Either<L, R>
Creates a Left value (typically representing an error)
Creates a Right value (typically representing success)