fabrik_result 1.0.1 copy "fabrik_result: ^1.0.1" to clipboard
fabrik_result: ^1.0.1 copied to clipboard

A lightweight toolkit for functional-style types like Either, built for clarity and real-world use.

fabrik_result #

Lightweight, explicit result types for Dart and Flutter — model success, failure, and absence of values without exceptions or nulls.

pub.dev license pure dart


What's included #

Type Purpose
Either<L, R> Success (Right) or failure (Left) with exhaustive handling
Option<T> Value present (Some) or absent (None)
Unit Typed replacement for void in generic APIs

Installation #

dependencies:
  fabrik_result: ^1.0.1
flutter pub get

Quick Start #

Either — handle failures explicitly #

Either<Failure, User> result = await getUser(id);

result.fold(
  (failure) => showError(failure.message),
  (user) => navigateToDashboard(user),
);

Return values using the helper functions:

Future<Either<Failure, User>> getUser(String id) async {
  try {
    final user = await api.fetchUser(id);
    return right(user);
  } catch (e) {
    return left(Failure(e.toString()));
  }
}

Option — model absence without null #

Option<User> cached = findCachedUser();

cached.fold(
  () => showLoginScreen(),
  (user) => showDashboard(user),
);

Unit — type-safe void #

Use Unit when an operation succeeds but has nothing meaningful to return:

Future<Either<Failure, Unit>> saveSettings(Settings s) async {
  try {
    await storage.write(s);
    return right(unit);
  } catch (e) {
    return left(Failure(e.toString()));
  }
}

Extras #

Either also has side-effect helpers for imperative code:

result.onRight((user) => analytics.track('login'));
result.onLeft((failure) => logger.error(failure));

final user = result.rightOrNull;

Documentation #

Full API reference and guides at fabriktool.com


Contributing #

Found a bug or have a suggestion? Open an issue or pull request on GitHub.

Maintainers #

3
likes
160
points
383
downloads

Publisher

verified publisherfabriktool.com

Weekly Downloads

A lightweight toolkit for functional-style types like Either, built for clarity and real-world use.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on fabrik_result