Skip to content
pubscout

result_monad

4.0.0, released 8 months ago by myportal.social

Dart Result Monad for handling success/failure without exceptions

WASM-ready
$ flutter pub add result_monad

What it does

Provides a Result type with Ok and Error variants to represent successful or failed operations. It offers functional helpers for chaining, mapping, and matching results without throwing exceptions.

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

Use it when

  • Handling operations that may fail and you want to avoid try/catch
  • Implementing functional error handling pipelines
  • When you need explicit success/failure propagation

Skip it when

  • When you prefer traditional exception handling
  • When performance overhead of Result objects matters
  • When working with APIs that already use exceptions

Strengths

  • Type-safe success/failure representation
  • Composable functional helpers (andThen, map, fold)
  • No exception overhead
  • Clear intent in code

Weaknesses

  • Adds boilerplate for simple cases
  • Learning curve for functional patterns
  • May be overkill for small projects

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
import 'package:result_monad/result_monad.dart';

Result<double, String> invert(double value) {
  if (value == 0) {
    return Error('Cannot invert zero');
  }
  return Ok(1.0 / value);
}

void main() {
  invert(2).match(
    onSuccess: (v) => print('Inverse is: $v'),
    onError: (e, _) => print(e),
  );
}

Alternatives

Packages that do the same job and could replace result_monad.