{"id":13704677,"url":"https://github.com/igorw/compose","last_synced_at":"2025-04-12T20:35:18.589Z","repository":{"id":8095554,"uuid":"9510037","full_name":"igorw/compose","owner":"igorw","description":"Function composition.","archived":false,"fork":false,"pushed_at":"2014-02-10T21:02:05.000Z","size":155,"stargazers_count":84,"open_issues_count":1,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-21T15:52:31.201Z","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/igorw.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}},"created_at":"2013-04-17T23:54:52.000Z","updated_at":"2024-03-17T01:08:15.000Z","dependencies_parsed_at":"2022-09-01T08:50:17.865Z","dependency_job_id":null,"html_url":"https://github.com/igorw/compose","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Fcompose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Fcompose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Fcompose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorw%2Fcompose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorw","download_url":"https://codeload.github.com/igorw/compose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631221,"owners_count":21136550,"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":"2024-08-02T21:01:17.446Z","updated_at":"2025-04-12T20:35:18.564Z","avatar_url":"https://github.com/igorw.png","language":"PHP","funding_links":[],"categories":["杂项","目录","Miscellaneous","结构( Architectural )","Architectural Architectural"],"sub_categories":["数据结构和存储 Data Structure and Storage"],"readme":"# igorw/compose\n\nFunction composition.\n\nAllows you to stitch functions together to form a pipeline. This can be useful\nif you have to transform data in many steps and you want to describe those\nsteps on a high level.\n\n## compose\n\nGenerally, function composition means taking two functions `f` and `g`, and\nproducing a new function `z`, which applies `f` to the result of `g`.\n\n    z = compose(f, g)\n    ; z(x) =\u003e f(g(x))\n\nThis library provides a `compose` function that does just this.\n\n    $z = igorw\\compose($f, $g);\n    var_dump($z($x));\n\nIt supports an arbitrary number of functions to be composed via varargs.\n\n    $z = igorw\\compose($f, $g, $h, $i);\n\nThe innermost function (the last one in the list) can take an arbitrary number\nof arguments, whereas the others may only take a single argument.\n\n    $z = igorw\\compose($f, $g);\n    $z('a', 'b', 'c');\n    // =\u003e $f($g('a', 'b', 'c'))\n\n## pipeline\n\n`pipeline` is the same as `compose`, but the arguments are reversed. This is\nmore easy to read in some cases, because you can list the functions in the\norder they will be called.\n\nIt is quite similar to a unix pipe in that regard.\n\n## Examples\n\n    function transform_data($data) {\n        return [\n            'name' =\u003e $data['firstname'].' '.$data['lastname'],\n        ];\n    }\n\n    $transformJson = igorw\\pipeline(\n        function ($json) { return json_decode($json, true); },\n        'transform_data',\n        'json_encode'\n    );\n\n    $json = \u003c\u003c\u003cEOF\n    {\"firstname\": \"Igor\", \"lastname\": \"Wiedler\"}\n    {\"firstname\": \"Beau\", \"lastname\": \"Simensen\"}\n    EOF;\n\n    $list = explode(\"\\n\", $json);\n    $newList = array_map($transformJson, $list);\n    $newJson = implode(\"\\n\", $newList);\n\n    // =\u003e\n    // {\"name\": \"Igor Wiedler\"}\n    // {\"name\": \"Beau Simensen\"}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorw%2Fcompose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorw%2Fcompose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorw%2Fcompose/lists"}