{"id":18353177,"url":"https://github.com/reasno/composemixins","last_synced_at":"2025-04-06T11:33:19.080Z","repository":{"id":62533952,"uuid":"118552208","full_name":"Reasno/ComposeMixins","owner":"Reasno","description":"ComposeMixins is a tiny but extendable PHP library for function composition.","archived":false,"fork":false,"pushed_at":"2018-06-15T15:17:47.000Z","size":14,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-21T22:41:32.027Z","etag":null,"topics":["compose","function-composition","functional-programming","php"],"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/Reasno.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}},"created_at":"2018-01-23T03:26:40.000Z","updated_at":"2018-06-15T15:17:48.000Z","dependencies_parsed_at":"2022-11-02T15:15:17.537Z","dependency_job_id":null,"html_url":"https://github.com/Reasno/ComposeMixins","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reasno%2FComposeMixins","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reasno%2FComposeMixins/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reasno%2FComposeMixins/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reasno%2FComposeMixins/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Reasno","download_url":"https://codeload.github.com/Reasno/ComposeMixins/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478152,"owners_count":20945258,"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":["compose","function-composition","functional-programming","php"],"created_at":"2024-11-05T21:38:47.686Z","updated_at":"2025-04-06T11:33:18.699Z","avatar_url":"https://github.com/Reasno.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ComposeMixins\nComposeMixins is a tiny but extendable PHP library for function composition. \n\n## Installation\n```bash\n# in your project root\ncomposer require reasno/compose-mixins\n```\n\n## Examples\n```php\nuse function Reasno\\Helpers\\composeMixins;\nuse Reasno\\Helpers\\Recipe;\n\n$c = composeMixins(new Recipe('pipe'), /* callable */ $a, /* callable */ $b);\n$result = $c($input); //Use the composed function\n\n```\n\n$c becomes a composition of function $a and function $b. You can verify it with the following snippet.\n\n```php\n$result1 = $c($input);\n$result2 = $a($b($input));\n\nvar_dump($result1 === $result2); //true\n```\n\n## API\n```php\nfunction composeMixins(Recipe $recipe, callable ...$mixins) \n```\n\n## Recipes\nThis library comes with a few (most frequently used) built in recipes. These recipes define how functions are composed together.\n\n* pipe: h(x) = g(f(x))\n* map: h(list) =  array_map(g, (array_map(f, list))) \n* all: returns true if all functions (eg. f(x), g(x)...) return true.\n* any: returns true if any function returns true.\n\nTo use any recipe, create new instance with their names passed into constructor.\n```php\nnew Recipe('map');\n```\n\nYou can create new recipes on the fly. Just pass in a closure.\n```php\n/* use a different handler each time the composed function is called */\n$r = Recipe::fromCallable(function(...$fns){\n\tstatic $i = 0;\n\treturn function($input) use (\u0026$i, $fns){\n\t\ttry{\n\t\t\treturn $fns[$i++]($input);\n\t\t} catch( Error $e ){\n\t\t\treturn null;\n\t\t}\n\n\t};\n});\n```\n\nYou can define your own RecipeHandlers in your own code, and pass it to the recipe constructor.\n```php\nClass MyRecipeHandler{\n\t//...\n}\n$CustomRecipe = new Recipe('fancy', ['handler' =\u003e 'MyRecipeHandler']);\n```\nPlease take a look at [RecipeHandler.php](https://github.com/Reasno/ComposeMixins/blob/master/src/RecipeHandler.php) in this library to learn how to write your own handlers.\n\n## Caveat\n* Functions composed with ```map``` and ```collapse``` recipes also accept ```Traversable``` as input.\n* For ```all``` and ```any``` recipes, all functions are always evaluated regardless of their return values.\n\n## Testing\nPHPUnit is overkill for this project. To do a simple test, execute ```php tests/composeMixinsTest.php``` and see if all assertions pass.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freasno%2Fcomposemixins","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freasno%2Fcomposemixins","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freasno%2Fcomposemixins/lists"}