Skip to content
pubscout

either_option

2.0.0, released 5 years ago by an unverified publisher

A simple library for error handling with Either and Option functional programming types.

WASM-ready
$ flutter pub add either_option
Source repository

What it does

Provides Either and Option monad abstractions to handle missing or erroneous values and optional data safely in Dart and Flutter projects.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want functional-style error handling using Either instead of throwing exceptions.
  • You need to represent optional values explicitly using Option, Some, and None.

Skip it when

  • You prefer traditional try-catch exception handling.
  • You already use a comprehensive functional programming library that includes Either and Option.

Strengths

  • Lightweight and simple to understand.
  • Brings popular functional patterns from languages like Scala and Haskell to Dart.

Weaknesses

  • Limited feature set compared to fully-fledged functional programming libraries.
  • Minimal documentation outside of basic README examples.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

Add either_option to pubspec.yaml dependencies.

Future<Either<ServerError, User>> getUser(int id) async {
  final res = await http.get(baseUrl);
  if (res.statusCode == 200) {
    return Right(User.fromJson(json.decode(res.body)));
  }
  return Left(ServerError("Error"));
}

Alternatives

Packages that do the same job and could replace either_option.

  • dart_either

    Either monad for Dart and Flutter supporting type-safe error handling and railway-oriented programming.

  • rust_core

    A pure Dart implementation of Rust patterns like Result, Option, Cell, Slice, and Array.

  • anyhow

    Dart implementation of Rust's Result monad type and anyhow crate for error handling.

  • structured_async

    Structured asynchronous programming and cancellable futures for Dart.

Works with

Packages commonly used together with either_option: ones it builds on, ones built on it, and its own family.