{"id":36213818,"url":"https://github.com/mohamedmaher-dev/data_result","last_synced_at":"2026-01-11T04:36:49.996Z","repository":{"id":330719255,"uuid":"1123777800","full_name":"mohamedmaher-dev/data_result","owner":"mohamedmaher-dev","description":"A lightweight, type-safe result type for Dart that elegantly handles success and failure states without exceptions. Perfect for clean error handling in your Dart and Flutter applications.","archived":false,"fork":false,"pushed_at":"2025-12-27T15:51:08.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-29T08:49:48.508Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohamedmaher-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-27T15:48:28.000Z","updated_at":"2025-12-27T15:53:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mohamedmaher-dev/data_result","commit_stats":null,"previous_names":["mohamedmaher-dev/data_result"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mohamedmaher-dev/data_result","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedmaher-dev%2Fdata_result","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedmaher-dev%2Fdata_result/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedmaher-dev%2Fdata_result/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedmaher-dev%2Fdata_result/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohamedmaher-dev","download_url":"https://codeload.github.com/mohamedmaher-dev/data_result/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedmaher-dev%2Fdata_result/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28284964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T03:48:11.750Z","status":"ssl_error","status_checked_at":"2026-01-11T03:48:02.765Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-11T04:36:49.266Z","updated_at":"2026-01-11T04:36:49.987Z","avatar_url":"https://github.com/mohamedmaher-dev.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Result\n\nA lightweight, type-safe alternative to Either/Result types for Dart and Flutter.\n\n[![pub package](https://img.shields.io/pub/v/data_result.svg)](https://pub.dev/packages/data_result)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n## Installation\n\n```yaml\ndependencies:\n  data_result: ^1.0.0\n```\n\n## Quick Start\n\nCreate your result type by extending `DataResult`:\n\n```dart\nimport 'package:data_result/data_result.dart';\n\nclass ApiResult\u003cT\u003e extends DataResult\u003cT, String\u003e {\n  ApiResult.success(super.data) : super.success();\n  ApiResult.failure(super.error) : super.failure();\n}\n```\n\nUse it in your functions:\n\n```dart\nFuture\u003cApiResult\u003cUser\u003e\u003e fetchUser(int id) async {\n  try {\n    final response = await http.get(Uri.parse('api.example.com/users/$id'));\n    if (response.statusCode == 200) {\n      return ApiResult.success(User.fromJson(response.body));\n    }\n    return ApiResult.failure('HTTP ${response.statusCode}');\n  } catch (e) {\n    return ApiResult.failure('Network error: $e');\n  }\n}\n```\n\nHandle the result:\n\n```dart\nfinal result = await fetchUser(123);\n\nresult.when(\n  success: (user) =\u003e print('User: $user'),\n  error: (error) =\u003e print('Error: $error'),\n);\n```\n\n## API\n\n**Create Results:**\n\n- `YourResult.success(data)` - Success result\n- `YourResult.failure(error)` - Failure result\n\n**Check Status:**\n\n- `result.isSuccess` - Check if successful\n- `result.data` - Get success data (or null)\n- `result.failure` - Get failure data (or null)\n\n**Handle Results:**\n\n- `result.when(success: ..., error: ...)` - Handle both cases\n- `result.whenOrNull(success: ..., failure: ...)` - Handle one case\n\n## Examples\n\n**Validation:**\n\n```dart\nclass ValidationResult\u003cT\u003e extends DataResult\u003cT, List\u003cString\u003e\u003e {\n  ValidationResult.success(super.data) : super.success();\n  ValidationResult.failure(super.errors) : super.failure();\n}\n\nValidationResult\u003cString\u003e validateEmail(String email) {\n  final errors = \u003cString\u003e[];\n  if (email.isEmpty) errors.add('Email required');\n  if (!email.contains('@')) errors.add('Invalid email');\n\n  return errors.isEmpty\n    ? ValidationResult.success(email)\n    : ValidationResult.failure(errors);\n}\n```\n\n**Database:**\n\n```dart\nclass DbResult\u003cT\u003e extends DataResult\u003cT, String\u003e {\n  DbResult.success(super.data) : super.success();\n  DbResult.failure(super.error) : super.failure();\n}\n\nDbResult\u003cUser\u003e saveUser(User user) {\n  try {\n    database.insert(user);\n    return DbResult.success(user);\n  } catch (e) {\n    return DbResult.failure('Save failed: $e');\n  }\n}\n```\n\n## Comparison with Either Packages\n\nPackages like [dart_either](https://pub.dev/packages/dart_either), [dartz](https://pub.dev/packages/dartz), and [fpdart](https://pub.dev/packages/fpdart) are powerful functional programming libraries with advanced features. **data_result** takes a different approach focused on simplicity and clarity.\n\n### When to Choose data_result\n\n**data_result** is perfect when you want:\n\n- Clear, self-documenting code with `success`/`failure` naming\n- Minimal learning curve for your team\n- Zero dependencies\n- Simple error handling without FP complexity\n\n```dart\n// Clear naming - no memorization needed\nclass ApiResult\u003cT\u003e extends DataResult\u003cT, String\u003e {\n  ApiResult.success(super.data) : super.success();\n  ApiResult.failure(super.error) : super.failure();\n}\n\nApiResult\u003cUser\u003e result = ApiResult.success(user);\nresult.when(\n  success: (user) =\u003e handleSuccess(user),  // Instantly clear\n  error: (error) =\u003e handleError(error),\n);\n```\n\n### When to Choose Either Packages\n\n**Either packages** are great when you need:\n\n- Advanced functional programming patterns (monad comprehensions, traverse, etc.)\n- Rich API with 50+ methods for complex transformations\n- Integration with FP ecosystems\n- Team familiar with FP concepts like `Left`/`Right`\n\n```dart\n// Functional programming approach\nEither\u003cString, User\u003e result = Either.right(user);\nresult.fold(\n  ifLeft: (error) =\u003e handleError(error),\n  ifRight: (user) =\u003e handleSuccess(user),\n);\n```\n\n### Key Differences\n\n| Feature          | dart_either/dartz/fpdart          | data_result             |\n| ---------------- | --------------------------------- | ----------------------- |\n| **Philosophy**   | Functional programming            | Pragmatic simplicity    |\n| **Naming**       | `Left`/`Right`                    | `success`/`failure`     |\n| **API**          | Comprehensive (50+ methods)       | Minimal (3 methods)     |\n| **Dependencies** | Has dependencies                  | Zero dependencies       |\n| **Use Case**     | Complex FP workflows              | Simple error handling   |\n| **Best For**     | FP enthusiasts, advanced patterns | Everyone, readable code |\n\n### The Bottom Line\n\nBoth approaches are valid:\n\n- Choose **Either packages** if you're doing functional programming and need advanced features\n- Choose **data_result** if you want clear, simple error handling that any developer can understand\n\n**data_result** exists because not every project needs the complexity of full Either monads. Sometimes you just want clean, readable error handling.\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamedmaher-dev%2Fdata_result","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohamedmaher-dev%2Fdata_result","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamedmaher-dev%2Fdata_result/lists"}