Repository navigation
Immutable
release. Only release title and notes can be modified.
https://pub.dev/packages/dart_either/versions/2.5.0
Selective error capture
- Added
ErrorMappers.only<E, L>, which adapts a typed error mapper to the
existingErrorMapper<L>interface. Matching errors and their subtypes are
mapped, while non-matching errors retain their original object and stack trace.
Errors thrown by the typed mapper propagate unchanged. ErrorMappers.onlycomposes withEither.tryCatch,Either.tryCatchAsync,
Future.toEitherFuture, andStream.toEitherStream.registerFatalError<T>()andErrorMappers.only<E, L>()filter in
complementary directions: registration globally excludes a type from every
mapper, whileErrorMappers.onlyselects one type for an individual mapper.
Global exclusion runs first.
final Either<String, int> result = Either.tryCatch(
action: () => throw const FormatException('invalid integer'),
errorMapper: ErrorMappers.only(
(FormatException error, StackTrace stackTrace) => error.message,
),
); // Either.Left(invalid integer)Typed nullable construction
- Added
Either.fromNullableOrElse, which converts a non-null value toRight
and lazily creates a typedLeftwhen the value isnull. TheifNull
callback runs once only fornull, and errors from it propagate unchanged. - Deprecated
Either.fromNullable(value)without changing its 2.x behavior.
UseEither.fromNullableOrElse<void, R>(value, ifNull: () {})to
preserveEither<void, R>andLeft(null). In 3.0.0,
Either.fromNullablewill adopt the typed, lazyifNullsignature.
Either.fromNullableOrElse<String, int>(
null,
ifNull: () => 'missing',
); // Either.Left(missing)
Either.fromNullableOrElse<String, int>(
42,
ifNull: () => 'missing',
); // Either.Right(42)Either value equality and hashing
LeftandRighthash codes now combine a branch-specific discriminator
with the active payload hash, avoiding systematic collisions between
same-payload values in different branches. Equality is unchanged: it uses
identity or same-branch payload equality and ignores generic type arguments.
Quality assurance
- Added deterministic semantic-law and API-coherence tests for
map,
flatMap,mapLeft,bimap, andswap, plus sequential traversal and
synchronous and asynchronous binding scopes. The async coherence cases
include real asynchronous suspension.
Collection interoperability
- Clarified how to use the
BuiltListresults oftraverse,sequence,
parTraverseN, andparSequenceN: pass them directly to APIs accepting
Iterable, use.asList()for an unmodifiableList, or.toList()for a
mutableList. The resulting lists use identity equality, so keep
BuiltListif you want==to compare their contents.
What's Changed
Full Changelog: 2.4.0...2.5.0