Either<L, R> class sealed

A type that represents a value of one of two possible types (a disjoint union). Instances of Either are either an instance of Left or Right.

By convention, Left is used for failure and Right is used for success.

Available extensions
Annotations
  • @Freezed.new()

Constructors

Either.left(L value)
Represents the left side of the disjoint union (by convention, an error).
const
factory
Either.right(R value)
Represents the right side of the disjoint union (by convention, a success).
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isLeft bool
True if this is Left.
no setter
isRight bool
True if this is Right.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value Object?
no setterinherited

Methods

fold<T>(T onLeft(L left), T onRight(R right)) → T
Folds the Either into a single value, applying onLeft if this is Left, and onRight if this is Right.
map<TResult extends Object?>({required TResult left(Left<L, R> value), required TResult right(Right<L, R> value)}) → TResult

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

A switch-like method, using callbacks.
mapLeft<L2>(L2 combiner(L left)) Either<L2, R>
Maps the left value, leaving the right value unchanged.
mapOrNull<TResult extends Object?>({TResult? left(Left<L, R> value)?, TResult? right(Right<L, R> value)?}) → TResult?

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

A variant of map that fallback to returning null.
mapRight<R2>(R2 combiner(R right)) Either<L, R2>
Maps the right value, leaving the left value unchanged.
maybeMap<TResult extends Object?>({TResult left(Left<L, R> value)?, TResult right(Right<L, R> value)?, required TResult orElse()}) → TResult

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

A variant of map that fallback to returning orElse.
maybeWhen<TResult extends Object?>({TResult left(L value)?, TResult right(R value)?, required TResult orElse()}) → TResult

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

A variant of when that fallback to an orElse callback.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
when<TResult extends Object?>({required TResult left(L value), required TResult right(R value)}) → TResult

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

A switch-like method, using callbacks.
whenOrNull<TResult extends Object?>({TResult? left(L value)?, TResult? right(R value)?}) → TResult?

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

A variant of when that fallback to returning null

Operators

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