{"id":15937168,"url":"https://github.com/inmanturbo/functional-library","last_synced_at":"2026-01-23T05:36:55.355Z","repository":{"id":252830283,"uuid":"841572474","full_name":"inmanturbo/functional-library","owner":"inmanturbo","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-19T21:59:47.000Z","size":37,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-29T00:56:18.426Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/inmanturbo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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-08-12T17:11:57.000Z","updated_at":"2024-08-19T21:59:50.000Z","dependencies_parsed_at":"2024-10-07T05:00:52.357Z","dependency_job_id":null,"html_url":"https://github.com/inmanturbo/functional-library","commit_stats":null,"previous_names":["inmanturbo/functional-library"],"tags_count":1,"template":false,"template_full_name":"spatie/package-skeleton-php","purl":"pkg:github/inmanturbo/functional-library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inmanturbo%2Ffunctional-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inmanturbo%2Ffunctional-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inmanturbo%2Ffunctional-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inmanturbo%2Ffunctional-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inmanturbo","download_url":"https://codeload.github.com/inmanturbo/functional-library/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inmanturbo%2Ffunctional-library/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28681009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T04:33:33.518Z","status":"ssl_error","status_checked_at":"2026-01-23T04:33:30.433Z","response_time":59,"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":"2024-10-07T05:00:43.124Z","updated_at":"2026-01-23T05:36:55.332Z","avatar_url":"https://github.com/inmanturbo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# create closure libraries with ease for functional programming with php\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/inmanturbo/functional-library.svg?style=flat-square)](https://packagist.org/packages/inmanturbo/functional-library)\n[![Tests](https://img.shields.io/github/actions/workflow/status/inmanturbo/functional-library/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/inmanturbo/functional-library/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/inmanturbo/functional-library.svg?style=flat-square)](https://packagist.org/packages/inmanturbo/functional-library)\n\nThis package makes it easy to export and autoload a library of anonymous functions or collections of anonymous functions using composer.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require inmanturbo/functional-library\n```\n\n## Usage\n\nTo create a library you can use the `HasFunctionalLibrary` trait, then you just have to implement\na static library method with named bool parameters for your available functions.\n\nYou then call `static::getLibrary` with all your parameters as its `args`.\n\nFinally, you create a static method called `closures()` with an associative array of your anonymous\nfunctions with  (string) keys corresponding to your library method's named params.\n\n## Example\n\n```php\nuse Inmanturbo\\FunctionalLibrary\\HasFunctionalLibrary;\n\nclass ExampleLibrary\n{\n    use HasFunctionalLibrary;\n\n    public static function library(bool $addOne = false, bool $addTwo = false)\n    {\n        return static::getLibrary(...func_get_args());\n    }\n\n    public static function closures()\n    {\n        return [\n            'addOne' =\u003e fn(int $number): int =\u003e $number + 1,\n            'addTwo' =\u003e fn(int $number): int =\u003e $number + 2,\n        ];\n    }\n}\n```\n\n## Example Usage\n\nThe above example creates the following testable api (using pest):\n\n```php\n[$addOne, $addTwo] = ExampleLibrary::library(addOne: true, addTwo: true);\nexpect($addOne(0))-\u003etoBe(1);\nexpect($addTwo(0))-\u003etoBe(2);\n\n// Test a single option\n$addOne = ExampleLibrary::library(addOne: true);\n\nexpect($addOne(0))-\u003etoBe(1);\n\n// Test no options (should return all available options)\n[$addOne, $addTwo] = ExampleLibrary::library();\n\nexpect($addOne(0))-\u003etoBe(1);\nexpect($addTwo(0))-\u003etoBe(2);\n```\n\nNow you can put your anonymous functions into scoped static libraries and find them using static analysis by their named arguments, or by inspecting the `closures()` method's return value.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [inmanturbo](https://github.com/inmanturbo)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finmanturbo%2Ffunctional-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finmanturbo%2Ffunctional-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finmanturbo%2Ffunctional-library/lists"}