{"id":22764602,"url":"https://github.com/kuria/iterable","last_synced_at":"2026-05-03T02:44:34.063Z","repository":{"id":57009940,"uuid":"149038330","full_name":"kuria/iterable","owner":"kuria","description":"Utilities for dealing with PHP's iterators and the iterable type","archived":false,"fork":false,"pushed_at":"2023-04-22T14:38:40.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-22T01:32:23.173Z","etag":null,"topics":["array","iterable","list","php"],"latest_commit_sha":null,"homepage":"","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/kuria.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","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":"2018-09-16T21:42:23.000Z","updated_at":"2023-09-19T17:45:36.000Z","dependencies_parsed_at":"2025-02-05T12:12:05.397Z","dependency_job_id":"1c0b661f-7baa-4598-b8c6-f78140399b44","html_url":"https://github.com/kuria/iterable","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kuria/iterable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Fiterable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Fiterable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Fiterable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Fiterable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kuria","download_url":"https://codeload.github.com/kuria/iterable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Fiterable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32556771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T00:31:16.350Z","status":"online","status_checked_at":"2026-05-03T02:00:09.297Z","response_time":103,"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":["array","iterable","list","php"],"created_at":"2024-12-11T12:09:28.499Z","updated_at":"2026-05-03T02:44:34.039Z","avatar_url":"https://github.com/kuria.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Iterable\n########\n\nUtilities for dealing with PHP's iterators and the iterable type.\n\n.. image:: https://travis-ci.com/kuria/iterable.svg?branch=master\n  :target: https://travis-ci.com/kuria/iterable\n\n.. contents::\n\n\nFeatures\n********\n\n- converting iterable values to arrays\n- caching iterator\n\n\nRequirements\n************\n\n- PHP 7.1+\n\n\nUsage\n*****\n\n``IterableHelper::toArray()``\n=============================\n\nConvert an iterable value to an array.\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Iterable\\IterableHelper;\n\n   $array = IterableHelper::toArray($iterable);\n\n- if the value is already an array, it is returned unchanged\n- if an iterator yields multiple values with the same key, only\n  the last value will be present in the array\n\n\n``IterableHelper::toList()``\n============================\n\nConvert an iterable value to an array with consecutive integer indexes.\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Iterable\\IterableHelper;\n\n   $list = IterableHelper::toList($iterable);\n\n- if the value is already an array, only its values will be returned\n  (keys are discarded)\n- if the value is traversable, all its values will be returned\n\n\n``CachingIterator``\n===================\n\n``CachingIterator`` can be used to wrap any ``\\Traversable`` instance so\nit can rewinded, counted and iterated multiple times.\n\n- as the traversable is iterated, its key-value pairs are cached in memory\n- the cached key-value pairs are reused for future iterations\n- when the traversable is fully iterated, the internal reference to it is dropped\n  (since it is no longer needed)\n\nThis is mostly useful with `generators \u003chttp://php.net/manual/en/language.generators.php\u003e`_\nor other non-rewindable traversables.\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Iterable\\Iterator\\CachingIterator;\n\n   function generator()\n   {\n       yield random_int(0, 99);\n       yield random_int(100, 199);\n       yield random_int(200, 299);\n   }\n\n   $cachingIterator = new CachingIterator(generator());\n\n   print_r(iterator_to_array($cachingIterator));\n   print_r(iterator_to_array($cachingIterator));\n   var_dump(count($cachingIterator));\n\nOutput:\n\n::\n\n  Array\n  (\n      [0] =\u003e 29\n      [1] =\u003e 107\n      [2] =\u003e 249\n  )\n  Array\n  (\n      [0] =\u003e 29\n      [1] =\u003e 107\n      [2] =\u003e 249\n  )\n  int(3)\n\n.. NOTE::\n\n   Your numbers will vary, but the output is meant to demonstrate that\n   the yielded pairs have indeed been cached.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuria%2Fiterable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuria%2Fiterable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuria%2Fiterable/lists"}