{"id":23067473,"url":"https://github.com/pyldin601/php-result","last_synced_at":"2025-09-11T07:36:53.939Z","repository":{"id":8902300,"uuid":"60153040","full_name":"pyldin601/php-result","owner":"pyldin601","description":"Abstraction that represents result of something","archived":false,"fork":false,"pushed_at":"2023-12-15T05:53:30.000Z","size":29,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-11T06:21:59.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyldin601.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-06-01T06:57:21.000Z","updated_at":"2016-10-28T07:32:02.000Z","dependencies_parsed_at":"2024-12-16T05:17:14.262Z","dependency_job_id":"e92016cc-d12d-40a2-a18a-91d286dde86a","html_url":"https://github.com/pyldin601/php-result","commit_stats":null,"previous_names":["pldin601/php-result"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/pyldin601/php-result","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyldin601%2Fphp-result","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyldin601%2Fphp-result/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyldin601%2Fphp-result/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyldin601%2Fphp-result/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyldin601","download_url":"https://codeload.github.com/pyldin601/php-result/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyldin601%2Fphp-result/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274595524,"owners_count":25314017,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-12-16T05:17:08.804Z","updated_at":"2025-09-11T07:36:53.887Z","avatar_url":"https://github.com/pyldin601.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-result\n[![Build Status](https://travis-ci.org/pldin601/php-result.svg?branch=master)](https://travis-ci.org/pldin601/php-result)\n[![Code Climate](https://codeclimate.com/github/pldin601/php-result/badges/gpa.svg)](https://codeclimate.com/github/pldin601/php-result)\n[![Test Coverage](https://codeclimate.com/github/pldin601/php-result/badges/coverage.svg)](https://codeclimate.com/github/pldin601/php-result/coverage)\n[![Issue Count](https://codeclimate.com/github/pldin601/php-result/badges/issue_count.svg)](https://codeclimate.com/github/pldin601/php-result)\n\nResult is an abstraction that can be used for returning and propagating errors.\nResult can be `ok`, representing success and containing a value,\nor `fail`, representing error and containing an error value.\n\nInspired by Rust's module `std::result`.\n\n## Functions\n```php\nuse Result as R;\n\nR\\ok('foo');\nR\\fail($value);\n\nR\\resultify($callable, ...$args);\nR\\notNull($callable, ...$args);\nR\\tryCatch($callable, $exceptionTransformCallable, ...$args);\n\nR\\isOk($result);\nR\\isFail($result);\n\nR\\ifOk($result, $callable);\nR\\ifFail($result, $callable);\n\nR\\getOrThrow($result, $exceptionClass);\n\nR\\bind($result, $callable);\nR\\pipeline(...$callables);\n```\n\n## Pipeline example\n```php\nuse Result as R;\n\n\n$readFile = function($filename) {\n    return R\\with($filename, 'file_exists', 'file_get_contents', function () {\n        return \"Can't read the file.\";\n    });\n}\n\n$proceedFile = function($content) {\n    $transform = function ($exception) {\n        return $exception-\u003egetMessage();\n    };\n\n    return R\\tryCatch('doSomethingWithContent', $transform, $content);\n}\n\n$saveFile = function($filename) {\n    return function ($content) use ($filename) {\n        $bytesWritten = file_put_contents($filename, $content);\n\n        return $bytesWritten === false\n            ? R\\fail(\"Can't save the file!\")\n            : R\\ok();\n    }\n}\n\n$pipeline = R\\pipeline($readFile, $proceedFile, $saveFile('/tmp/output_file'));\n\n$result = $pipeline('/tmp/input_file');\n\nR\\ifOk($result, function () {\n    echo 'File successfully saved.';\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyldin601%2Fphp-result","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyldin601%2Fphp-result","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyldin601%2Fphp-result/lists"}