{"id":26954628,"url":"https://github.com/evandersondev/resultfy","last_synced_at":"2025-04-03T02:18:36.148Z","repository":{"id":268112078,"uuid":"903352238","full_name":"evandersondev/resultfy","owner":"evandersondev","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-14T12:08:40.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-14T12:29:17.202Z","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/evandersondev.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}},"created_at":"2024-12-14T11:39:24.000Z","updated_at":"2024-12-14T12:08:43.000Z","dependencies_parsed_at":"2024-12-14T12:28:24.460Z","dependency_job_id":"98e79157-fb53-4ad5-bcbd-c87e58b20d0d","html_url":"https://github.com/evandersondev/resultfy","commit_stats":null,"previous_names":["evandersondev/result","evandersondev/resultify"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evandersondev%2Fresultfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evandersondev%2Fresultfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evandersondev%2Fresultfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evandersondev%2Fresultfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evandersondev","download_url":"https://codeload.github.com/evandersondev/resultfy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922227,"owners_count":20855345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2025-04-03T02:18:35.564Z","updated_at":"2025-04-03T02:18:36.140Z","avatar_url":"https://github.com/evandersondev.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Result Library for Dart\n\nA robust utility for handling success and error states in a functional style.\n\n## Features\n\n- Encapsulate success and failure states using `Result`.\n- Transform values with `map` and `flatMap`.\n- Handle errors gracefully with `mapError`.\n- Combine multiple `Result` objects.\n- Simplify async operations with `fromAsync`.\n- Convenient extensions for ergonomics.\n\n## Installation\n\nAdd the following dependency to your `pubspec.yaml`:\n\n```yaml\ndependencies:\n  resultfy: ^1.0.0\n```\n\nThen, run:\n\n```bash\nflutter pub get\n```\n\n## Getting Started\n\n### Basic Usage\n\n```dart\nimport 'package:resultfy/resultfy.dart';\n\nvoid main() {\n  // Creating a success result\n  final success = Result.success(\"Operation completed successfully\");\n  print(success); // Output: Result\u003cString\u003e.success(Operation completed successfully)\n\n  // Creating a failure result\n  final failure = Result.failure(Exception(\"An error occurred\"));\n  print(failure); // Output: Result\u003cString\u003e.failure(Exception: An error occurred)\n\n  // Handling results\n  success.fold(\n    (value) =\u003e print(\"Success: $value\"),\n    (error) =\u003e print(\"Failure: $error\"),\n  );\n\n  failure.fold(\n    (value) =\u003e print(\"Success: $value\"),\n    (error) =\u003e print(\"Failure: $error\"),\n  );\n}\n```\n\n### Mapping Success and Failure\n\n```dart\nfinal success = Result.success(42);\nfinal transformedSuccess = success.map((value) =\u003e \"Value is \\$value\");\nprint(transformedSuccess); // Output: Result\u003cString\u003e.success(Value is 42)\n\nfinal failure = Result.failure(\"Initial Error\");\nfinal transformedFailure = failure.mapError((error) =\u003e \"Updated Error: \\$error\");\nprint(transformedFailure); // Output: Result\u003cString\u003e.failure(Updated Error: Initial Error)\n```\n\n### Combining Results\n\n```dart\nfinal results = [\n  Result.success(1),\n  Result.success(2),\n  Result.success(3),\n];\n\nfinal combined = Result.combine(results);\nprint(combined); // Output: Result\u003cList\u003cint\u003e\u003e.success([1, 2, 3])\n\nfinal resultsWithFailure = [\n  Result.success(1),\n  Result.failure(\"Error\"),\n];\n\nfinal combinedWithFailure = Result.combine(resultsWithFailure);\nprint(combinedWithFailure); // Output: Result\u003cList\u003cint\u003e\u003e.failure(Error)\n```\n\n### Asynchronous Usage\n\n```dart\nFuture\u003cResult\u003cString\u003e\u003e fetchData() async {\n  return await Result.fromAsync(() async {\n    if (DateTime.now().millisecondsSinceEpoch % 2 == 0) {\n      return \"Fetched data\";\n    } else {\n      throw Exception(\"Fetch error\");\n    }\n  });\n}\n\nvoid main() async {\n  final result = await fetchData();\n\n  result.fold(\n    (value) =\u003e print(\"Success: \\$value\"),\n    (error) =\u003e print(\"Failure: \\$error\"),\n  );\n}\n```\n\n### Extensions for Improved Ergonomics\n\n```dart\nfinal result = Result.success(10);\nfinal mapped = result.mapSuccess((value) =\u003e value * 2);\nprint(mapped); // Output: Result\u003cint\u003e.success(20)\n\nfinal errorHandled = result.mapFailure((error) =\u003e \"Handled: \\$error\");\nprint(errorHandled); // Output: Result\u003cint\u003e.success(20)\n```\n\n## Testing\n\n### Mocking Success and Failure\n\n```dart\nimport 'package:test/test.dart';\nimport 'package:resultfy/resultfy.dart';\n\nvoid main() {\n  test('Success result works correctly', () {\n    final result = Result.success(100);\n\n    expect(result.isSuccess, true);\n    expect(result.getOrNull(), 100);\n    expect(result.exceptionOrNull(), null);\n  });\n\n  test('Failure result works correctly', () {\n    final result = Result.failure(Exception(\"Test error\"));\n\n    expect(result.isFailure, true);\n    expect(result.getOrNull(), null);\n    expect(result.exceptionOrNull(), isA\u003cException\u003e());\n  });\n\n  test('Mapping success works correctly', () {\n    final result = Result.success(50);\n    final mapped = result.map((value) =\u003e value * 2);\n\n    expect(mapped.getOrNull(), 100);\n  });\n\n  test('Handling failure works correctly', () {\n    final result = Result.failure(\"Error\");\n    final handled = result.mapError((error) =\u003e \"Handled: \\$error\");\n\n    expect(handled.exceptionOrNull(), \"Handled: Error\");\n  });\n}\n```\n\n## API Reference\n\n### `Result\u003cT\u003e`\n\n| Method                   | Description                                             |\n| ------------------------ | ------------------------------------------------------- |\n| `Result.success(T)`      | Creates a success result with a value.                  |\n| `Result.failure(Object)` | Creates a failure result with an error.                 |\n| `isSuccess`              | Returns `true` if the result is a success.              |\n| `isFailure`              | Returns `true` if the result is a failure.              |\n| `exceptionOrNull()`      | Returns the error if it's a failure, or `null`.         |\n| `getOrNull()`            | Returns the value if it's a success, or `null`.         |\n| `getOrElse()`            | Returns the value or a default value if it's a failure. |\n| `fold()`                 | Executes a function based on success or failure.        |\n| `map()`                  | Transforms the success value with a function.           |\n| `flatMap()`              | Transforms the success value into another `Result`.     |\n| `mapError()`             | Transforms the error with a function.                   |\n\n### Utility Methods\n\n| Method        | Description                                    |\n| ------------- | ---------------------------------------------- |\n| `combine()`   | Combines multiple `Result` objects into one.   |\n| `fromAsync()` | Wraps an asynchronous operation in a `Result`. |\n\n### Extensions\n\n| Extension      | Description                        |\n| -------------- | ---------------------------------- |\n| `mapSuccess()` | Maps the success value if present. |\n| `mapFailure()` | Maps the error value if present.   |\n\n## Contributing\n\nContributions are welcome! Please open issues or submit pull requests on the [GitHub repository](https://github.com/evandersondev/resultfy).\n\n## License\n\nThis library is licensed under the MIT License. See the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevandersondev%2Fresultfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevandersondev%2Fresultfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevandersondev%2Fresultfy/lists"}