{"id":22772890,"url":"https://github.com/baguettephp/functools","last_synced_at":"2025-10-18T01:11:07.944Z","repository":{"id":26142789,"uuid":"29587859","full_name":"BaguettePHP/Functools","owner":"BaguettePHP","description":"Functional toolbox","archived":false,"fork":false,"pushed_at":"2016-07-03T00:25:24.000Z","size":652,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-22T11:30:52.863Z","etag":null,"topics":["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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BaguettePHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2015-01-21T12:09:38.000Z","updated_at":"2019-10-28T10:42:28.000Z","dependencies_parsed_at":"2022-08-01T05:48:33.848Z","dependency_job_id":null,"html_url":"https://github.com/BaguettePHP/Functools","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/BaguettePHP/Functools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaguettePHP%2FFunctools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaguettePHP%2FFunctools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaguettePHP%2FFunctools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaguettePHP%2FFunctools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaguettePHP","download_url":"https://codeload.github.com/BaguettePHP/Functools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaguettePHP%2FFunctools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279446546,"owners_count":26171763,"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-10-17T02:00:07.504Z","response_time":56,"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":["functional-programming","php"],"created_at":"2024-12-11T17:10:02.869Z","updated_at":"2025-10-18T01:11:07.914Z","avatar_url":"https://github.com/BaguettePHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Teto Functools\n==============\n\n[![Package version](http://img.shields.io/packagist/v/zonuexe/functools.svg?style=flat)](https://packagist.org/packages/zonuexe/functools)\n[![Build Status](https://travis-ci.org/BaguettePHP/Functools.svg?branch=master)](https://travis-ci.org/BaguettePHP/Functools)\n[![Packagist](http://img.shields.io/packagist/dt/zonuexe/functools.svg?style=flat)](https://packagist.org/packages/zonuexe/functools)\n[![Coverage Status](https://coveralls.io/repos/BaguettePHP/Functools/badge.svg)](https://coveralls.io/r/BaguettePHP/Functools)\n\nFunctional toolbox for PHP\n\nInstallation\n------------\n\n### Composer\n\n```\ncomposer require zonuexe/functools\n```\n\nFeatures\n--------\n\n* `Functools\\Operator`\n  * Operator Expression wrapper\n    * Binary operator `1 + 2` `$a === \"abc\"` `$date instanceof '\\Datetime'`\n    * Conditional operator `$cond ? $then : $else`\n    * Lazy Conditional operator `$cond($v) ? $then($v) : $else($v)` ([thunk](http://en.wikipedia.org/wiki/Thunk))\n  * [Referential transparent](http://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29) version [sorting array functions](http://php.net/manual/array.sorting.php).\n    * You can `array_map(f::op('ksort'), $arrays)` !\n  * Language-construct wrapper\n    * `echo`, `print`, `eval`, `require`, `require_once`, `include`, `include_once`\n    * limited support: `array`, `isset`, `empty`\n* `Functools::partial(callable $callback, array $arguments, int $pos)`\n  * Partial application for [callable](http://php.net/manual/language.types.callable.php) (`arary_map` friendly)\n* `Functools::arity(callable $callback)`\n  * Analyze [arity](http://en.wikipedia.org/wiki/Arity)(number of arguments) of `$callback`.\n* `Functools::curry(callable $callback)`\n  * [Currying](http://en.wikipedia.org/wiki/Currying) `$callback` object.\n* `Functools::op(string $symbol, [array $arguments, int $pos])`\n  * Get callable object (and partial application.)\n* `Functools::compose(callable $callback,...)`\n  * [Function composition](http://en.wikipedia.org/wiki/Function_composition_%28computer_science%29).\n* `Functools::pipe(mixed $value, callable $callback...)`\n  * [Pipeline](https://en.wikipedia.org/wiki/Pipeline_(Unix)) like functions composing\n* `Functools::tuple(mixed $item,...)`\n  * Make n-[Tuple](http://en.wikipedia.org/wiki/Tuple).\n* `Functools::fix(callable $callback)`\n  * [Anonymous recursion](http://en.wikipedia.org/wiki/Anonymous_recursion) ([fixed-point combinator](http://en.wikipedia.org/wiki/Fixed-point_combinator))\n* `Functools::memoize(callable $callback, [array $cache])`\n  * Function optimizer using [Memoization](https://en.wikipedia.org/wiki/Memoization).\n  * This feature will help in optimization of transparent reference explicit definition equation.\n\nIteration\n---------\n\nThis library does not have iterator. You will be able to combine it by selecting a favorite of iterator library.\n\n* PHP [`array`](http://php.net/manual/language.types.array.php) and functions\n  * [PHP: array_map - Manual](http://php.net/manual/function.array-map.php)\n  * [PHP: array_reduce - Manual](http://php.net/manual/function.array-reduce.php)\n  * [PHP: array_filter - Manual](http://php.net/manual/function.array-filter.php)\n* [Underbar.php - A collection processing library for PHP, like Underscore.js.](http://emonkak.github.io/underbar.php/)\n  * [emonkak/underbar.php](https://github.com/emonkak/underbar.php)\n* Ginq\n  * [akanehara/ginq](https://github.com/akanehara/ginq)\n* nikic\\iter\n  * [nikic/iter](https://github.com/nikic/iter)\n\nUsage\n-----\n\nJapanese version: http://qiita.com/tadsan/items/abc52f0739ab5b4e781b\n\n### Short syntax\n\n```php\nuse Teto\\Functools as f;\n```\n\n### f::partial()\n\n```php\n$comma = f::partial(\"implode\", [\", \"]);\n$comma(range(1, 10));\n// \"1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\n$join_10 = f::partial(\"implode\", [1 =\u003e range(1, 10)], 0);\n$join_10(\"@\");\n// \"1@2@3@4@5@6@7@8@9@10\"\n$join_10(\"\\\\\");\n=\u003e \"1\\\\2\\\\3\\\\4\\\\5\\\\6\\\\7\\\\8\\\\9\\\\10\"\n\n$sleep3 = f::partial(\"sleep\", [3]);\n$sleep3();\n$sleep3(\"foo\"); // Error!\n\n$sleep3 = f::partial(\"sleep\", [3], -1);\n$sleep3(\"foo\"); // OK!\n```\n\n### f::op()\n\n```php\n$add = f::op(\"+\");\n$add(2, 3); // (2 + 3) === 5\n\n$add_1 = f::op(\"+\", [1]);\n$add_1(4);  // (1 + 4) === 5\n\n$half = f::op(\"/\", [1 =\u003e 2], 0);\n$half(10);  // (10 / 2) === 5\n```\n\n### f::tuple()\n\n```php\n$teto  = f::tuple(\"Teto Kasane\",  31, \"2008-04-01\", \"Baguette\");\n$ritsu = f::tuple(\"Ritsu Namine\", 6,  \"2009-10-02\", \"Napa cabbage\");\n\n// index access\n$teto[0]; // \"Teto Kasane\"\n$teto[1]; // 31\n$teto[2]; // \"2008-04-01\"\n$teto[3]; // \"Baguette\"\n\n// property access\n\n$tetop  = f::tuple(\"name\", \"Teto Kasane\",  \"age\", 31, \"birthday\", \"2008-04-01\", \"item\", \"Baguette\");\n$ritsup = f::tuple(\"name\", \"Ritsu Namine\", \"age\",  6, \"birthday\", \"2009-10-02\", \"item\", \"Napa cabbage\");\n$tetop-\u003epget(\"name\");     // \"Teto Kasane\"\n$tetop-\u003epget(\"age\");      // 31\n$tetop-\u003epget(\"birthday\"); // \"2008-04-01\"\n$tetop-\u003epget(\"item\");     // \"Baguette\"\n```\n\n### f::fix()\n\n```php\n$fib = f::fix(function ($fib) {\n    return function ($x) use ($fib) {\n        return ($x \u003c 2) ? 1 : $fib($x - 1) + $fib($x -2);\n    };\n});\n\n$fib(6); // 13\n```\n\n### f::memoize()\n\n```php\n// simple fibonacci function. But, very very slow.\n$fib1 = function ($n) use (\u0026$fib1) {\n    return ($n \u003c 2) ? $n : $fib1($n - 1) + $fib1($n - 2);\n};\n\n// simple fibonacci function too. very fast!\n$fib2 = f::memoize(function ($n) use (\u0026$fib2) {\n    return ($n \u003c 2) ? $n : $fib2($n - 1) + $fib2($n - 2);\n}, [0, 1]);\n```\n\nCopyright\n---------\n\nsee `./LICENSE`.\n\n    Functional toolbox\n    Copyright (c) 2015 USAMI Kenta \u003ctadsan@zonu.me\u003e\n\nTeto Kasane\n-----------\n\nI love [Teto Kasane](http://utau.wikia.com/wiki/Teto_Kasane). (ja: [Teto Kasane official site](http://kasaneteto.jp/))\n\n```\n　　　　　 　r /\n　 ＿＿ , --ヽ!-- .､＿\n　! 　｀/::::;::::ヽ l\n　!二二!::／}::::丿ハﾆ|\n　!ﾆニ.|:／　ﾉ／ }::::}ｺ\n　L二lイ　　0´　0 ,':ﾉｺ\n　lヽﾉ/ﾍ､ ''　▽_ノイ ソ\n 　ソ´ ／}｀ｽ /￣￣￣￣/\n　　　.(_:;つ/  0401 /　ｶﾀｶﾀ\n ￣￣￣￣￣＼/＿＿＿＿/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaguettephp%2Ffunctools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaguettephp%2Ffunctools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaguettephp%2Ffunctools/lists"}