Simple Either - a Dart library designed to facilitate functional programming through the implementation of the Either monad. This package provides a structured approach for handling two possible outcomes (typically success and failure) in a functional paradigm.
- Either Monad Implementation
- Left and Right classes for handling success and failure
To start using the "simple_either" package, follow these steps:
- Add the dependency to your project's
pubspec.yaml
file:
dependencies:
simple_either: ^1.0.0
Save the file and run pub get
in your project directory to fetch and install the package.
- Import the package into your project:
import 'package:simple_either/simple_either.dart';
Explore the examples below to see how to use the "simple_either" package.
import 'package:simple_either/simple_either.dart';
import 'dart:async';
Either<Error, SuccessType> syncFunction() {
try {
// Do something that might throw an error
return Right(SuccessType());
} catch (e) {
return Left(Error());
}
}
Future<Either<Error, SuccessType>> asyncFunction() async {
try {
// Do something that might throw an error
return Right(SuccessType());
} catch (e) {
return Left(Error());
}
}
Check the GitHub repository for any additional information, issues, or community discussions.