dart_either
2.5.0, released 6 weeks ago by hoc081098.dev
Either monad for Dart and Flutter supporting type-safe error handling and railway-oriented programming.
What it does
Provides an Either<L, R> data type representing one of two possible values (Left for errors, Right for success). Includes tools for monad comprehensions, async mapping, error capturing, and railroad-oriented programming.
AI-written summary of version 2.5.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want explicit, type-safe error handling instead of uncaught exceptions.
- You need railway-oriented programming and monad comprehensions in Dart.
Skip it when
- Your team prefers standard Dart exceptions and try-catch blocks.
- You already use full-featured functional programming libraries like dartz or fpdart that provide their own Either monad.
Strengths
- Lightweight and focused specifically on the Either monad without importing an entire FP library.
- Fully documented with tests, sync/async monad comprehensions, and selective error capture.
Weaknesses
- Adds an alternative error-handling paradigm that other developers on the team may need to learn.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
final Either<String, int> right = Either.right(10);
final Either<String, String> mapRight = right.map((a) => 'String: $a');Alternatives
Packages that do the same job and could replace dart_either.
- pubspec_parse
Parse pubspec.yaml files with a type‑safe API and detailed error reporting.
93Compare - fpdart
Functional programming types and patterns for Dart and Flutter.
71Compare - either_option
A simple library for error handling with Either and Option functional programming types.
42Compare - result_type
A Result type representing success or failure in Dart
50Compare
Works with
Packages commonly used together with dart_either: ones it builds on, ones built on it, and its own family.