{"id":13624092,"url":"https://github.com/Athari/YaLinqo","last_synced_at":"2025-04-15T20:33:10.122Z","repository":{"id":3273361,"uuid":"4312864","full_name":"Athari/YaLinqo","owner":"Athari","description":"Yet Another LINQ to Objects for PHP [Simplified BSD]","archived":false,"fork":false,"pushed_at":"2024-01-23T09:10:14.000Z","size":1006,"stargazers_count":447,"open_issues_count":19,"forks_count":39,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-07T23:07:40.983Z","etag":null,"topics":["functional","functional-programming","library","linq","linq-to-objects","php","query","statistics","underscore"],"latest_commit_sha":null,"homepage":"https://athari.github.io/YaLinqo","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"spree/spree","license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Athari.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2012-05-13T07:28:45.000Z","updated_at":"2025-03-19T04:54:24.000Z","dependencies_parsed_at":"2024-01-03T02:23:02.088Z","dependency_job_id":"6a3f0ff6-b267-40f2-b91f-1f827ec0a17f","html_url":"https://github.com/Athari/YaLinqo","commit_stats":{"total_commits":163,"total_committers":4,"mean_commits":40.75,"dds":0.1288343558282209,"last_synced_commit":"939469772b36d4d454836681e0be2f220cf1e5cb"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Athari%2FYaLinqo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Athari%2FYaLinqo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Athari%2FYaLinqo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Athari%2FYaLinqo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Athari","download_url":"https://codeload.github.com/Athari/YaLinqo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249148300,"owners_count":21220511,"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":["functional","functional-programming","library","linq","linq-to-objects","php","query","statistics","underscore"],"created_at":"2024-08-01T21:01:38.736Z","updated_at":"2025-04-15T20:33:09.754Z","avatar_url":"https://github.com/Athari.png","language":"PHP","readme":"# *YaLinqo: Yet Another LINQ to Objects for PHP*\n\n[![Travis CI Status](https://img.shields.io/travis/Athari/YaLinqo.svg)](https://travis-ci.org/Athari/YaLinqo)\n[![Coveralls Coverage](https://img.shields.io/coveralls/Athari/YaLinqo/master.svg)](https://coveralls.io/r/Athari/YaLinqo)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/Athari/YaLinqo.svg)](https://scrutinizer-ci.com/g/Athari/YaLinqo)\n[![SensioLabs Insight Check](https://img.shields.io/sensiolabs/i/d1273f86-85e3-4076-a037-a40062906329.svg)](https://insight.sensiolabs.com/projects/d1273f86-85e3-4076-a037-a40062906329)\n[![VersionEye Dependencies](https://www.versioneye.com/php/athari:yalinqo/badge.svg)](https://www.versioneye.com/php/athari:yalinqo)\u003cbr\u003e\n[![Packagist Downloads](https://img.shields.io/packagist/dt/athari/yalinqo.svg)](https://packagist.org/packages/athari/yalinqo)\n[![VersionEye References](https://www.versioneye.com/php/athari:yalinqo/reference_badge.svg)](https://www.versioneye.com/php/athari:yalinqo/references)\n[![Packagist Version](https://img.shields.io/packagist/v/athari/yalinqo.svg)](https://packagist.org/packages/athari/yalinqo)\n[![GitHub License](https://img.shields.io/github/license/Athari/YaLinqo.svg)](license.md)\n\n* [**Online documentation**](http://athari.github.io/YaLinqo)\n* [**GitHub repository**](https://github.com/Athari/YaLinqo)\n\nFeatures\n========\n\n* The most complete port of .NET LINQ to PHP, with [many additional methods](#implemented-methods).\n* Lazy evaluation, error messages and other behavior of original LINQ.\n* [Detailed PHPDoc and online reference](http://athari.github.io/YaLinqo) based on PHPDoc for all methods. Articles are adapted from original LINQ documentation from MSDN.\n* 100% unit test coverage.\n* Best performance among full-featured LINQ ports (YaLinqo, Ginq, Pinq), at least 2x faster than the closest competitor, see [performance tests](https://github.com/Athari/YaLinqoPerf).\n* Callback functions can be specified as closures (like `function ($v) { return $v; }`), PHP \"function pointers\" (either strings like `'strnatcmp'` or arrays like `array($object, 'methodName')`), string \"lambdas\" using various syntaxes (`'\"$k = $v\"'`, `'$v ==\u003e $v+1'`, `'($v, $k) ==\u003e $v + $k'`, `'($v, $k) ==\u003e { return $v + $k; }'`).\n* Keys are as important as values. Most callback functions receive both values and the keys; transformations can be applied to both values and the keys; keys are never lost during transformations, if possible.\n* SPL interfaces `Iterator`, `IteratorAggregate` etc. are used throughout the code and can be used interchangeably with Enumerable.\n* Redundant collection classes are avoided, native PHP arrays are used everywhere.\n* Composer support ([package](https://packagist.org/packages/athari/yalinqo) on Packagist).\n* No external dependencies.\n\nImplemented methods\n===================\n\nSome methods had to be renamed, because their names are reserved keywords. Original methods names are given in parenthesis.\n\n* **Generation**: cycle, emptyEnum (empty), from, generate, toInfinity, toNegativeInfinity, matches, returnEnum (return), range, rangeDown, rangeTo, repeat, split;\n* **Projection and filtering**: cast, ofType, select, selectMany, where;\n* **Ordering**: orderBy, orderByDescending, orderByDir, thenBy, thenByDescending, thenByDir;\n* **Joining and grouping**: groupJoin, join, groupBy;\n* **Aggregation**: aggregate, aggregateOrDefault, average, count, max, maxBy, min, minBy, sum;\n* **Set**: all, any, append, concat, contains, distinct, except, intersect, prepend, union;\n* **Pagination**: elementAt, elementAtOrDefault, first, firstOrDefault, firstOrFallback, last, lastOrDefault, lastOrFallback, single, singleOrDefault, singleOrFallback, indexOf, lastIndexOf, findIndex, findLastIndex, skip, skipWhile, take, takeWhile;\n* **Conversion**: toArray, toArrayDeep, toList, toListDeep, toDictionary, toJSON, toLookup, toKeys, toValues, toObject, toString;\n* **Actions**: call (do), each (forEach), write, writeLine.\n\nIn total, more than 80 methods.\n\nExample\n=======\n\n*Process sample data:*\n\n```php\n// Data\n$products = array(\n    array('name' =\u003e 'Keyboard',    'catId' =\u003e 'hw', 'quantity' =\u003e  10, 'id' =\u003e 1),\n    array('name' =\u003e 'Mouse',       'catId' =\u003e 'hw', 'quantity' =\u003e  20, 'id' =\u003e 2),\n    array('name' =\u003e 'Monitor',     'catId' =\u003e 'hw', 'quantity' =\u003e   0, 'id' =\u003e 3),\n    array('name' =\u003e 'Joystick',    'catId' =\u003e 'hw', 'quantity' =\u003e  15, 'id' =\u003e 4),\n    array('name' =\u003e 'CPU',         'catId' =\u003e 'hw', 'quantity' =\u003e  15, 'id' =\u003e 5),\n    array('name' =\u003e 'Motherboard', 'catId' =\u003e 'hw', 'quantity' =\u003e  11, 'id' =\u003e 6),\n    array('name' =\u003e 'Windows',     'catId' =\u003e 'os', 'quantity' =\u003e 666, 'id' =\u003e 7),\n    array('name' =\u003e 'Linux',       'catId' =\u003e 'os', 'quantity' =\u003e 666, 'id' =\u003e 8),\n    array('name' =\u003e 'Mac',         'catId' =\u003e 'os', 'quantity' =\u003e 666, 'id' =\u003e 9),\n);\n$categories = array(\n    array('name' =\u003e 'Hardware',          'id' =\u003e 'hw'),\n    array('name' =\u003e 'Operating systems', 'id' =\u003e 'os'),\n);\n\n// Put products with non-zero quantity into matching categories;\n// sort categories by name;\n// sort products within categories by quantity descending, then by name.\n$result = from($categories)\n    -\u003eorderBy('$cat ==\u003e $cat[\"name\"]')\n    -\u003egroupJoin(\n        from($products)\n            -\u003ewhere('$prod ==\u003e $prod[\"quantity\"] \u003e 0')\n            -\u003eorderByDescending('$prod ==\u003e $prod[\"quantity\"]')\n            -\u003ethenBy('$prod ==\u003e $prod[\"name\"]'),\n        '$cat ==\u003e $cat[\"id\"]', '$prod ==\u003e $prod[\"catId\"]',\n        '($cat, $prods) ==\u003e array(\n            \"name\" =\u003e $cat[\"name\"],\n            \"products\" =\u003e $prods\n        )'\n    );\n\n// Alternative shorter syntax using default variable names\n$result2 = from($categories)\n    -\u003eorderBy('$v[\"name\"]')\n    -\u003egroupJoin(\n        from($products)\n            -\u003ewhere('$v[\"quantity\"] \u003e 0')\n            -\u003eorderByDescending('$v[\"quantity\"]')\n            -\u003ethenBy('$v[\"name\"]'),\n        '$v[\"id\"]', '$v[\"catId\"]',\n        'array(\n            \"name\" =\u003e $v[\"name\"],\n            \"products\" =\u003e $e\n        )'\n    );\n\n// Closure syntax, maximum support in IDEs, but verbose and hard to read\n$result3 = from($categories)\n    -\u003eorderBy(function ($cat) { return $cat['name']; })\n    -\u003egroupJoin(\n        from($products)\n            -\u003ewhere(function ($prod) { return $prod[\"quantity\"] \u003e 0; })\n            -\u003eorderByDescending(function ($prod) { return $prod[\"quantity\"]; })\n            -\u003ethenBy(function ($prod) { return $prod[\"name\"]; }),\n        function ($cat) { return $cat[\"id\"]; },\n        function ($prod) { return $prod[\"catId\"]; },\n        function ($cat, $prods) {\n            return array(\n                \"name\" =\u003e $cat[\"name\"],\n                \"products\" =\u003e $prods\n            );\n        }\n    );\n\nprint_r($result-\u003etoArrayDeep());\n```\n\n*Output (compacted):*\n\n```\nArray (\n    [hw] =\u003e Array (\n        [name] =\u003e Hardware\n        [products] =\u003e Array (\n            [0] =\u003e Array ( [name] =\u003e Mouse       [catId] =\u003e hw [quantity] =\u003e  20 [id] =\u003e 2 )\n            [1] =\u003e Array ( [name] =\u003e CPU         [catId] =\u003e hw [quantity] =\u003e  15 [id] =\u003e 5 )\n            [2] =\u003e Array ( [name] =\u003e Joystick    [catId] =\u003e hw [quantity] =\u003e  15 [id] =\u003e 4 )\n            [3] =\u003e Array ( [name] =\u003e Motherboard [catId] =\u003e hw [quantity] =\u003e  11 [id] =\u003e 6 )\n            [4] =\u003e Array ( [name] =\u003e Keyboard    [catId] =\u003e hw [quantity] =\u003e  10 [id] =\u003e 1 )\n        )\n    )\n    [os] =\u003e Array (\n        [name] =\u003e Operating systems\n        [products] =\u003e Array (\n            [0] =\u003e Array ( [name] =\u003e Linux       [catId] =\u003e os [quantity] =\u003e 666 [id] =\u003e 8 )\n            [1] =\u003e Array ( [name] =\u003e Mac         [catId] =\u003e os [quantity] =\u003e 666 [id] =\u003e 9 )\n            [2] =\u003e Array ( [name] =\u003e Windows     [catId] =\u003e os [quantity] =\u003e 666 [id] =\u003e 7 )\n        )\n    )\n)\n```\n\nRequirements\n============\n\n* Version 1 (stable): PHP 5.3 or higher.\n* Version 2 (stable): PHP 5.5 or higher.\n* Version 3 (pre-alpha): PHP 7.0 or higher.\n\nUsage\n=====\n\nAdd to `composer.json`:\n\n```json\n{\n    \"require\": {\n        \"athari/yalinqo\": \"^2.0\"\n    }\n}\n```\n\nAdd to your PHP script:\n\n```php\nrequire_once 'vendor/autoloader.php';\nuse \\YaLinqo\\Enumerable;\n\n// 'from' can be called as a static method or via a global function shortcut\nEnumerable::from(array(1, 2, 3));\nfrom(array(1, 2, 3));\n```\n\nLicense\n=======\n\n[**Simplified BSD License**](license.md)  \nCopyright © 2012–2018, Alexander Prokhorov  \nAll rights reserved.\n\nLinks\n=====\n\n### YaLinqo Articles\n\n* **CodeProject** *(English):*\n  * [LINQ for PHP comparison: YaLinqo, Ginq, Pinq](http://www.codeproject.com/Articles/997238/LINQ-for-PHP-comparison-YaLinqo-Ginq-Pinq) — performance comparison of full-featured LINQ ports, with some additional information.\n\n* **Habrahabr** *(Russian):*\n  * [Comparison of old LINQ libraries](http://habrahabr.ru/post/147612/) — comparison of *LINQ for PHP*, *Phinq*, *PHPLinq* and *Plinq*, also *Underscore.php*.\n  * [YaLinqo 1.0 with updated comparison](http://habrahabr.ru/post/147848/) — explanation of architecture and design decisions.\n  * [YaLinqo 2.0](http://habrahabr.ru/post/229763/) — switch to PHP 5.5 with generators support and related changes.\n  * [LINQ for PHP: speed matters](http://habrahabr.ru/post/259155/) — performance comparison of full-featured LINQ ports (YaLinqo, Ginq, Pinq).\n\n* **Other** *(English):*\n  * Tute Wall: [How to use Linq in PHP](http://tutewall.com/how-to-use-linq-in-php-part-01/) by *Mr. X* — a series of posts covering basic usage of YaLinqo. \n\n### Related projects\n\n* [**linq.js**](http://linqjs.codeplex.com/) — LINQ for JavaScript. The one and only complete port of .NET LINQ to JavaScript.\n* [**Underscore.js**](http://documentcloud.github.com/underscore/) — library for functional programming in JavaScript. Similar to LINQ, but different method names and no lazy evaluation.\n* [**Underscore.php**](http://brianhaveri.github.com/Underscore.php/) — port of Underscore.js to PHP.\n* [**RxPHP**](https://github.com/ReactiveX/RxPHP) — reactive (push) counterpart of the active (pull) LINQ, port of Rx.NET.\n* [**YaLinqoPerf**](https://github.com/Athari/YaLinqoPerf) — collection of performance tests comparing raw PHP, array functions, YaLinqo, YaLinqo with string lambdas, Ginq, Ginq with property accessors, Pinq.","funding_links":[],"categories":["Table of Contents","数据结构和存储 Data Structure and Storage","目录","PHP","Libraries","Implementations"],"sub_categories":["Data Structure and Storage","数据结构和存储 Data Structure and Storage","[PHP](https://github.com/php/php-src)","Miscs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAthari%2FYaLinqo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAthari%2FYaLinqo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAthari%2FYaLinqo/lists"}