outcome 0.0.1 copy "outcome: ^0.0.1" to clipboard
outcome: ^0.0.1 copied to clipboard

A dart library that provides a functional approach to error handling.

outcome #

A dart library that provides a functional approach to error handling.

Installation #

Add the following dependencies to your project.

dependencies:
  outcome: ^0.0.1

Usage #

import 'package:outcome/outcome.dart';

void main() {
  final result = divide(10, 2);
  result.fold(
        (error) => print('Error is $error'),
        (value) => print('Result is $value'),
  );
}

/// Returns the result of dividing [a] by [b]. If [b] is 0, returns an [Error].
Either<Error, int> divide(int a, int b) {
  if (b == 0) {
    return Left(Error.divisionByZero);
  } else {
    return Right(a ~/ b);
  }
}

/// An error that can occur when dividing two numbers.
enum Error {
  /// Occurs when the divisor is 0.
  divisionByZero,
}

Maintainer #

3
likes
160
points
39
downloads

Publisher

unverified uploader

Weekly Downloads

A dart library that provides a functional approach to error handling.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on outcome