mayr_result 1.0.0
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.
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! ππ