{"id":21467451,"url":"https://github.com/elusivecodes/fyrecollection","last_synced_at":"2026-01-27T18:07:35.788Z","repository":{"id":257792950,"uuid":"862324205","full_name":"elusivecodes/FyreCollection","owner":"elusivecodes","description":"FyreCollection is a free, open-source collection library for PHP.","archived":false,"fork":false,"pushed_at":"2024-10-17T13:42:14.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-19T19:27:42.625Z","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/elusivecodes.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-24T12:13:14.000Z","updated_at":"2024-10-17T13:42:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"a6710acc-6818-46c4-a5f0-5b870b3d95f9","html_url":"https://github.com/elusivecodes/FyreCollection","commit_stats":null,"previous_names":["elusivecodes/fyrecollection"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCollection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCollection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCollection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCollection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreCollection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017557,"owners_count":17560539,"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-11-23T08:18:08.269Z","updated_at":"2026-01-27T18:07:30.753Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreCollection\r\n\r\n**FyreCollection** is a free, open-source immutable collection library for *PHP*.\r\n\r\nIt is a modern library, and features support for generators and lazy evaluation.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Collection Creation](#collection-creation)\r\n- [Methods](#methods)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/collection\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Collection\\Collection;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$source` can be either an array, a *Closure* that returns a *Generator*, or a *Traversable* or *JsonSerializable* object.\r\n\r\n```php\r\n$collection = new Collection($source);\r\n```\r\n\r\nThe *Collection* is an implementation of an *Iterator* and can be used in a `foreach` loop.\r\n\r\n```php\r\nforeach ($collection AS $key =\u003e $value) { }\r\n```\r\n\r\n\r\n## Collection Creation\r\n\r\n**Empty**\r\n\r\nCreate an empty collection.\r\n\r\n```php\r\n$collection = Collection::empty();\r\n```\r\n\r\n**Range**\r\n\r\nCreate a collection for a range of numbers.\r\n\r\n- `$from` is an integer representing the start of the range.\r\n- `$to` is an integer representing the end of the range.\r\n\r\n```php\r\n$collection = Collection::range($from, $to);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Avg**\r\n\r\nGet the average value of a key.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *null*.\r\n\r\n```php\r\n$avg = $collection-\u003eavg($valuePath);\r\n```\r\n\r\n**Cache**\r\n\r\nCache the computed values via a new collection.\r\n\r\n```php\r\n$cache = $collection-\u003ecache();\r\n```\r\n\r\n**Chunk**\r\n\r\nSplit the collection into chunks.\r\n\r\n- `$size` is a number representing the size of each chunk.\r\n- `$preserveKey` is a boolean indicating whether to preserve the keys, and will default to *false*.\r\n\r\n```php\r\n$chunk = $collection-\u003echunk($size, $preserveKeys);\r\n```\r\n\r\n**Collect**\r\n\r\nCollect the computed values into a new collection.\r\n\r\n```php\r\n$collect = $collection-\u003ecollect();\r\n```\r\n\r\n**Combine**\r\n\r\nRe-index the items in the collection by a given key, using a given value.\r\n\r\n- `$keyPath` is a string or array representing the path to the new key, or a *Closure* that receives the item and key as arguments, and should return the new key.\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value.\r\n\r\n```php\r\n$combine = $collection-\u003ecombine($keyPath, $valuePath);\r\n```\r\n\r\n**Count**\r\n\r\nCount all items in the collection.\r\n\r\n```php\r\n$count = $collection-\u003ecount();\r\n```\r\n\r\n**Count By**\r\n\r\nGroups the items in the collection by a given key, and count the number of items in each.\r\n\r\n- `$keyPath` is a string or array representing the path to the group key, or a *Closure* that receives the item and key as arguments, and should return the group key.\r\n\r\n```php\r\n$countBy = $collection-\u003ecountBy($keyPath);\r\n```\r\n\r\n**Dot**\r\n\r\nFlatten a multi-dimensional collection using \"dot\" notation.\r\n\r\n```php\r\n$dot = $collection-\u003edot();\r\n```\r\n\r\n**Each**\r\n\r\nExecute a callback on each item in the collection.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments.\r\n\r\n```php\r\n$collection-\u003eeach($callback);\r\n```\r\n\r\n**Every**\r\n\r\nDetermine whether every item in the collection passes a callback.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$every = $collection-\u003eevery($callback);\r\n```\r\n\r\n**Except**\r\n\r\nReturn a collection without the specified keys.\r\n\r\n- `$keys` is an array containing the keys to remove.\r\n\r\n```php\r\n$except = $collection-\u003eexcept($callback);\r\n```\r\n\r\n**Extract**\r\n\r\nExtract values from the collection using \"dot\" notation.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value.\r\n\r\n```php\r\n$extract = $collection-\u003eextract($valuePath);\r\n``` \r\n\r\n**Filter**\r\n\r\nFilter items in the collection using a callback function.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$filter = $collection-\u003efilter($callback);\r\n``` \r\n\r\n**Find**\r\n\r\nFind the first value in the collection that passes a callback.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$find = $collection-\u003efind($callback);\r\n``` \r\n\r\n**Find Last**\r\n\r\nFind the last value in the collection that passes a callback.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$findLast = $collection-\u003efindLast($callback);\r\n``` \r\n\r\n**First**\r\n\r\nGet the first value in the collection.\r\n\r\n```php\r\n$first = $collection-\u003efirst();\r\n``` \r\n\r\n**Flatten**\r\n\r\nFlatten a multi-dimensional collection into a single level.\r\n\r\n- `$maxDepth` is a number representing the maximum depth to flatten, and will default to *PHP_INT_MAX*.\r\n\r\n```php\r\n$flatten = $collection-\u003eflattened($maxDepth);\r\n``` \r\n\r\n**Flip**\r\n\r\nSwap the keys and values of a collection.\r\n\r\n```php\r\n$flip = $collection-\u003eflip();\r\n``` \r\n\r\n**Group By**\r\n\r\nGroup the items in the collection by a given key.\r\n\r\n- `$keyPath` is a string or array representing the path to the new key, or a *Closure* that receives the item and key as arguments, and should return the new key.\r\n\r\n```php\r\n$groupBy = $collection-\u003egroupBy($keyPath);\r\n```\r\n\r\n**Includes**\r\n\r\nDetermine whether a given value exists in the collection.\r\n\r\n- `$value` is the value to test for.\r\n\r\n```php\r\n$includes = $collection-\u003eincludes($value);\r\n``` \r\n\r\n**Index By**\r\n\r\nRe-index the items in the collection by a given key.\r\n\r\n- `$keyPath` is a string or array representing the path to the new key, or a *Closure* that receives the item and key as arguments, and should return the new key.\r\n\r\n```php\r\n$indexBy = $collection-\u003eindexBy($keyPath);\r\n```\r\n\r\n**Index Of**\r\n\r\nSearch the collection for a given value and return the first key.\r\n\r\n- `$value` is the value to test for.\r\n\r\n```php\r\n$indexOf = $collection-\u003eindexOf($value);\r\n``` \r\n\r\n**Is Empty**\r\n\r\nDetermine whether the collection is empty.\r\n\r\n```php\r\n$isEmpty = $collection-\u003eisEmpty();\r\n```\r\n\r\n**Join**\r\n\r\nJoin the items in the collection using a specified separator.\r\n\r\n- `$glue` is a string representing the separator to join with.\r\n- `$finalGlue` is a string representing the final separator to join with, and will default to *null*.\r\n\r\n```php\r\n$join = $collection-\u003ejoin($glue, $finalGlue);\r\n``` \r\n\r\n**Keys**\r\n\r\nGet the keys in the collection.\r\n\r\n```php\r\n$keys = $collection-\u003ekeys();\r\n``` \r\n\r\n**Last**\r\n\r\nGet the last value in the collection.\r\n\r\n```php\r\n$last = $collection-\u003elast();\r\n``` \r\n\r\n**Last Index Of**\r\n\r\nSearch the collection for a given value and return the last key.\r\n\r\n- `$value` is the value to test for.\r\n\r\n```php\r\n$lastIndexOf = $collection-\u003elastIndexOf($value);\r\n``` \r\n\r\n**List Nested**\r\n\r\nFlatten nested items into a list.\r\n\r\n- `$order` is a string representing the order, and will default to *\"desc\"*.\r\n- `$nestingKey` is a string representing the nesting key, and will default to *\"children\"*.\r\n\r\n```php\r\n$listNested = $collection-\u003elistNested($order, $nestingKey);\r\n``` \r\n\r\n**Map**\r\n\r\nApply a callback to the items in the collection.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return the new value.\r\n\r\n```php\r\n$map = $collection-\u003emap($callback);\r\n``` \r\n\r\n**Max**\r\n\r\nGet the maximum value of a key.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *null*.\r\n\r\n```php\r\n$max = $collection-\u003emax($valuePath);\r\n```\r\n\r\n**Median**\r\n\r\nGet the median value of a key.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *null*.\r\n\r\n```php\r\n$median = $collection-\u003emedian($valuePath);\r\n```\r\n\r\n**Merge**\r\n\r\nMerge one or more iterables into the collection.\r\n\r\nAll arguments supplied must be either an array or *Iterator*, and will be merged with the collection.\r\n\r\n```php\r\n$merge = $collection-\u003emerge(...$iterables);\r\n```\r\n\r\n**Min**\r\n\r\nGet the minimum value of a key.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *null*.\r\n\r\n```php\r\n$min = $collection-\u003emin($valuePath);\r\n```\r\n\r\n**Nest**\r\n\r\nNest child items inside parent items.\r\n\r\n- `$idPath` is a string or array representing the path to the ID, or a *Closure* that receives the item and key as arguments, and should return the ID, and will default to *\"id\"*.\r\n- `$parentPath` is a string or array representing the path to the parent ID, or a *Closure* that receives the item and key as arguments, and should return the parent ID, and will default to *\"id\"*.\r\n- `$nestingKey` is a string representing the nesting key, and will default to *\"children\"*.\r\n\r\n```php\r\n$nest = $collection-\u003enest($idPath, $parentPath, $nestingKey);\r\n```\r\n\r\n**None**\r\n\r\nDetermine whether no items in the collection pass a callback.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$none = $collection-\u003enone($callback);\r\n``` \r\n\r\n**Only**\r\n\r\nReturn a Collection with only the specified keys.\r\n\r\n- `$keys` is an array containing the keys to include.\r\n\r\n```php\r\n$only = $collection-\u003eonly($callback);\r\n```\r\n\r\n**Print Nested**\r\n\r\nFormat nested list items based on depth.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *\"id\"*.\r\n- `$idPath` is a string or array representing the path to the ID, or a *Closure* that receives the item and key as arguments, and should return the ID, and will default to *\"id\"*.\r\n- `$nestingKey` is a string representing the nesting key, and will default to *\"children\"*.\r\n\r\n```php\r\n$printNested = $collection-\u003eprintNested($valuePath, $idPath, $prefix, $nestingKey);\r\n``` \r\n\r\n**Random Value**\r\n\r\nPull a random item out of the collection.\r\n\r\n```php\r\n$randomValue = $collection-\u003erandomValue();\r\n``` \r\n\r\n**Reduce**\r\n\r\nIteratively reduce the collection to a single value using a callback function.\r\n\r\n- `$callback` is a *Closure* that receives the accumulated value, item and key as arguments, and should return the next value.\r\n- `$initial` is the initial value to use, and will default to *null*.\r\n\r\n```php\r\n$reduce = $collection-\u003ereduce($callback, $initial);\r\n``` \r\n\r\n**Reject**\r\n\r\nExclude items in the collection using a callback function.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$reject = $collection-\u003ereject($callback);\r\n``` \r\n\r\n**Reverse**\r\n\r\nReverse the order of items in the collection.\r\n\r\n```php\r\n$reverse = $collection-\u003ereverse();\r\n``` \r\n\r\n**Shuffle**\r\n\r\nRandomize the order of items in the collection.\r\n\r\n```php\r\n$shuffle = $collection-\u003eshuffle();\r\n``` \r\n\r\n**Skip**\r\n\r\nSkip a number of items in the collection.\r\n\r\n- `$length` is a number representing the number of items to skip.\r\n\r\n```php\r\n$skip = $collection-\u003eskip($length);\r\n``` \r\n\r\n**Skip Until**\r\n\r\nSkip items in the collection until a callback returns *true*.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$skipUntil = $collection-\u003eskipUntil($callback);\r\n``` \r\n\r\n**Skip While**\r\n\r\nSkip items in the collection until a callback returns *false*.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$skipWhile = $collection-\u003eskipWhile($callback);\r\n``` \r\n\r\n**Some**\r\n\r\nDetermine whether some items in the collection pass a callback.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$some = $collection-\u003esome($callback);\r\n``` \r\n\r\n**Sort**\r\n\r\nSort the collection using a callback.\r\n\r\n- `$callback` is a *Closure* that receives 2 items to compare, and should return an integer to determine the sort order.\r\n\r\n```php\r\n$sort = $collection-\u003esort($callback);\r\n```\r\n\r\nAlternatively, you can sort the collection items in ascending order.\r\n\r\n- `$sort` is a number representing the sorting flag, and will default to *Collection::SORT_NATURAL*.\r\n\r\n```php\r\n$sort = $collection-\u003esort($sort);\r\n```\r\n\r\n**Sort By**\r\n\r\nSort the collection by a given key.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *null*.\r\n- `$sort` is a number representing the sorting flag, and will default to *Collection::SORT_NATURAL*.\r\n- `$descending` is a boolean indicating whether to sort in descending order, and will default to *false*.\r\n\r\n```php\r\n$sortBy = $collection-\u003esortBy($valuePath, $sort, $descending);\r\n```\r\n\r\n**Sum Of**\r\n\r\nGet the total sum of a key.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *null*.\r\n\r\n```php\r\n$sumOf = $collection-\u003esumOf($valuePath);\r\n```\r\n\r\n**Take**\r\n\r\nTake a number of items in the collection.\r\n\r\n- `$length` is a number representing the number of items to skip.\r\n\r\n```php\r\n$take = $collection-\u003etake($length);\r\n``` \r\n\r\n**Take Until**\r\n\r\nTake items in the collection until a callback returns *true*.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$takeUntil = $collection-\u003etakeUntil($callback);\r\n``` \r\n\r\n**Take While**\r\n\r\nTake items in the collection until a callback returns *false*.\r\n\r\n- `$callback` is a *Closure* that receives the item and key as arguments, and should return a boolean.\r\n\r\n```php\r\n$takeWhile = $collection-\u003etakeWhile($callback);\r\n``` \r\n\r\n**To Array**\r\n\r\nGet the items in the collection as an array.\r\n\r\n```php\r\n$array = $collection-\u003etoArray();\r\n```\r\n\r\n**To Json**\r\n\r\n```php\r\n$json = $collection-\u003etoJson();\r\n```\r\n\r\n**To List**\r\n\r\nGet the values in the collection as an array.\r\n\r\n```php\r\n$list = $collection-\u003etoList();\r\n```\r\n\r\n**Unique**\r\n\r\nGet the unique items in the collection based on a given key.\r\n\r\n- `$valuePath` is a string or array representing the path to the value, or a *Closure* that receives the item and key as arguments, and should return the value, and will default to *null*.\r\n- `$strict` is a boolean indicating whether to perform strict equality checks, and will default to *false*.\r\n\r\n```php\r\n$unique = $collection-\u003eunique($valuePath, $strict);\r\n```\r\n\r\n**Values**\r\n\r\nGet the values in the collection.\r\n\r\n```php\r\n$values = $collection-\u003evalues();\r\n```\r\n\r\n**Zip**\r\n\r\nZip one or more iterables with the collection.\r\n\r\nAll arguments supplied must be either an array or *Iterator*, and will be zipped with the collection.\r\n\r\n```php\r\n$zip = $collection-\u003ezip(...$iterables);\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrecollection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyrecollection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrecollection/lists"}