Skip to content

2.5.0 - Oct 12, 2026

Latest

Choose a tag to compare

@github-actions github-actions released this 12 Oct 17:15
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
    existing ErrorMapper<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.only composes with Either.tryCatch, Either.tryCatchAsync,
    Future.toEitherFuture, and Stream.toEitherStream.
  • registerFatalError<T>() and ErrorMappers.only<E, L>() filter in
    complementary directions: registration globally excludes a type from every
    mapper, while ErrorMappers.only selects 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 to Right
    and lazily creates a typed Left when the value is null. The ifNull
    callback runs once only for null, and errors from it propagate unchanged.
  • Deprecated Either.fromNullable(value) without changing its 2.x behavior.
    Use Either.fromNullableOrElse<void, R>(value, ifNull: () {}) to
    preserve Either<void, R> and Left(null). In 3.0.0,
    Either.fromNullable will adopt the typed, lazy ifNull signature.
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

  • Left and Right hash 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, and swap, plus sequential traversal and
    synchronous and asynchronous binding scopes. The async coherence cases
    include real asynchronous suspension.

Collection interoperability

  • Clarified how to use the BuiltList results of traverse, sequence,
    parTraverseN, and parSequenceN: pass them directly to APIs accepting
    Iterable, use .asList() for an unmodifiable List, or .toList() for a
    mutable List. The resulting lists use identity equality, so keep
    BuiltList if you want == to compare their contents.

What's Changed

Full Changelog: 2.4.0...2.5.0