{"id":42402739,"url":"https://github.com/preprocess/pre-short-closures","last_synced_at":"2026-01-28T01:26:36.867Z","repository":{"id":57053013,"uuid":"80178350","full_name":"preprocess/pre-short-closures","owner":"preprocess","description":null,"archived":false,"fork":false,"pushed_at":"2020-06-18T16:16:39.000Z","size":36,"stargazers_count":35,"open_issues_count":2,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-27T16:21:56.018Z","etag":null,"topics":["arrow","closure","macro","preprocessor"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/preprocess.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-27T03:30:11.000Z","updated_at":"2023-03-06T11:23:23.000Z","dependencies_parsed_at":"2022-08-24T00:10:07.850Z","dependency_job_id":null,"html_url":"https://github.com/preprocess/pre-short-closures","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/preprocess/pre-short-closures","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-short-closures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-short-closures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-short-closures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-short-closures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/preprocess","download_url":"https://codeload.github.com/preprocess/pre-short-closures/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-short-closures/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28831296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T23:29:49.665Z","status":"ssl_error","status_checked_at":"2026-01-27T23:25:58.379Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["arrow","closure","macro","preprocessor"],"created_at":"2026-01-28T01:26:36.300Z","updated_at":"2026-01-28T01:26:36.854Z","avatar_url":"https://github.com/preprocess.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Short Closures\n\nDocumentation can be found at [preprocess.io](https://preprocess.io#short-closures).\n\n\u003e **Since [this RFC](https://wiki.php.net/rfc/arrow_functions_v2) was approved, we have standardised on the same syntax.** We do still allow function bodies and return type hints, but everything in that RFC can be done, with the same syntax, as far back as Yay will allow (7.1).\n\nYou can use closures with similar semantics to Javascript:\n\n```php\n$files = array_map(\n    fn($path) =\u003e file_get_contents($path),\n    $paths\n);\n\n$needles = [\n    \"PHP\",\n    \"Go\",\n    \"Javascript\",\n];\n\n$matches = array_filter($files, fn($content = \"\") =\u003e {\n    foreach ($needles as $needle) {\n        if (stristr($content, $needle)) {\n            return true;\n        }\n    }\n\n    return false;\n});\n```\n\nThese are converted to:\n\n```php\n$files = array_map(\n    function ($path) {\n        return file_get_contents($path);\n    },\n    $paths\n);\n\n$needles = [\n    \"PHP\",\n    \"Go\",\n    \"Javascript\",\n];\n\n$matches = array_filter($files, [$needles = $needles ?? null, $needle = $needle ?? null, \"fn\" =\u003e function ($content = \"\") use (\u0026$needles, \u0026$needle) {\n    foreach ($needles as $needle) {\n        if (stristr($content, $needle)) {\n            return true;\n        }\n    }\n\n    return false;\n}][\"fn\"]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreprocess%2Fpre-short-closures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpreprocess%2Fpre-short-closures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreprocess%2Fpre-short-closures/lists"}