Thanks to visit codestin.com
Credit goes to pub.dev

mayr_result 1.0.0 copy "mayr_result: ^1.0.0" to clipboard
mayr_result: ^1.0.0 copied to clipboard

A lightweight functional-style Result type for Dart that represents success or failure outcomes. Simplifies error handling by replacing exceptions with safe, expressive result objects.

License Platform

Pub Version Pub.dev Score Pub Likes Pub.dev Publisher Downloads

Build Status Issues Last Commit Contributors

Result 🧩 #

A lightweight functional-style Result type for Dart that represents success (Ok) or failure (Err) outcomes.

Instead of throwing exceptions, Result lets you write clear, predictable, and composable code. Inspired by Rust’s Result<T, E> and Kotlin’s Result, it provides a safe way to handle operations that may fail.


✨ Features #

  • βœ… Simple, expressive success/failure handling
  • ⚑️ No exceptions β€” results you can trust
  • 🧠 Composable: then, catchError, and more
  • 🧩 Works seamlessly with async/await

πŸš€ Quick Start #

import 'package:result/result.dart';

MayrResult<int, String> divide(int a, int b) {
  if (b == 0) return Err('Cannot divide by zero');
  return Ok(a ~/ b);
}

void main() {
  final result = divide(10, 2);

  // Method 1
  result.when(
    ok: (value) => print('Result: $value'),
    err: (error) => throw error,
  );

  // Method 2
  if (result.isOk) {
    print(result.value);
  }

  if (result.isErr) {
    throw result.error;
  }

  // Method 3
  result.onOk((value) => print('Result: $value'));

  result.onErr((error) => throw error);
}

πŸ“’ Additional Information #

🀝 Contributing #

Contributions are highly welcome! If you have ideas for new extensions, improvements, or fixes, feel free to fork the repository and submit a pull request.

Please make sure to:

  • Follow the existing coding style.
  • Write tests for new features.
  • Update documentation if necessary.

Let's build something amazing together!


πŸ› Reporting Issues #

If you encounter a bug, unexpected behaviour, or have feature requests:

  • Open an issue on the repository.
  • Provide a clear description and steps to reproduce (if it's a bug).
  • Suggest improvements if you have any ideas.

Your feedback helps make the package better for everyone!


πŸ“œ Licence #

This package is licensed under the MIT License β€” which means you are free to use it for commercial and non-commercial projects, with proper attribution.

See the LICENSE file for more details.


🌟 Support #

If you find this package helpful, please consider giving it a ⭐️ on GitHub β€” it motivates and helps the project grow!

You can also support by:

  • Sharing the package with your friends, colleagues, and tech communities.
  • Using it in your projects and giving feedback.
  • Contributing new ideas, features, or improvements.

Every little bit of support counts! πŸš€πŸ’™

2
likes
140
points
153
downloads

Publisher

verified publishermayrlabs.com

Weekly Downloads

A lightweight functional-style Result type for Dart that represents success or failure outcomes. Simplifies error handling by replacing exceptions with safe, expressive result objects.

Repository (GitHub)
View/report issues

Topics

#result #utilities #dart #productivity #toolkit

Documentation

Documentation
API reference

License

MIT (license)

More

Packages that depend on mayr_result