{"id":22092108,"url":"https://github.com/krakphp/coll","last_synced_at":"2025-03-23T23:44:53.740Z","repository":{"id":57009016,"uuid":"57080852","full_name":"krakphp/coll","owner":"krakphp","description":"PHP Collections Library","archived":false,"fork":false,"pushed_at":"2016-04-25T22:43:15.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T09:06:26.752Z","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/krakphp.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":"2016-04-25T22:35:56.000Z","updated_at":"2016-04-25T22:36:17.000Z","dependencies_parsed_at":"2022-08-21T14:50:50.012Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/coll","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fcoll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fcoll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fcoll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fcoll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/coll/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186924,"owners_count":20574554,"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-12-01T03:08:21.206Z","updated_at":"2025-03-23T23:44:53.721Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coll (Collections)\n\nThe Collections library is yet another attempt to generate OO collections in php.\n\nCurrently, the only collection in here is the Set because that's the only collection PHP actually is missing.\n\n## Installation\n\n```\ncompose require krak/coll\n```\n\n## Usage\n\n### Set\n\nA set represents a set of unique values.\n\nThere are two interfaces for the Set type: `ConstSet` and `Set`.\n\nConst sets allow read access only whereas Sets allow read write access.\n\n```\n// const methods\npublic function get($value);\npublic function has($value);\npublic function count();\npublic function getIterator();\n\n// non-const methods\npublic function add($value);\npublic function remove($value);\n```\n\n```php\n\u003c?php\n\nuse Krak\\Coll\\Set;\n\n$s1 = new Set\\ArraySet();\n// or\n$s1 = Set\\ArraySet::create([1,2,3]);\n\n$s1-\u003eadd(4);\n$s2 = set\\union($s1, Set\\ArraySet::create([3,4]));\n\nset\\is_subset($s2, $s1); // returns true because s1 is a subset of s2\n\n// if you need to store object values\n\n// internally uses SplObjectStorage\n$oset = new Set\\ObjectSet();\n$oset-\u003eadd(new stdClass());\n\n// if you need to store values that work as array keys\n$hset = new Set\\HashSet();\n$hset-\u003eadd(['a' =\u003e 1]);\n\n// if you need to store any of those types of values\n$aset = new Set\\AnySet();\nset\\fill($aset, [1, [1], new stdClass()]);\n```\n\nEach is set does also work as an iterable and is countable\n\n```php\n\u003c?php\n\ncount($s1); // returns the count\nforeach ($s1 as $val) {\n    // iterate over the set values\n}\n```\n\nFor type hinting use, `Set` or `ConstSet`\n\n```php\n\u003c?php\n\nuse Krak\\Coll\\Set;\n\nfunction operate_on_mutable(Set\\Set $s1) {\n    // ...\n}\n\nfunction operate_on_immutable(Set\\ConstSet $s1) {\n    // ...\n}\n```\n\nAs seen earlier, we do have several set operation functions.\n\n```\n// similar to union, but can work with different typed set (AnySet and ArraySet)\nfunction join(ConstSet $s1, ConstSet $s2, $factory = null);\n// s1 + s2\nfunction union(ConstSet $s1, ConstSet $s2);\n// s1 * s2\nfunction intersect(ConstSet $s1, ConstSet $s2);\n// s1 - s2\nfunction difference(ConstSet $s1, ConstSet $s2);\n// compares to sets returns true if s2 is subset of s1\nfunction is_subset(ConstSet $s1, ConstSet $s2);\n// compares to sets returns true on equal\nfunction equals(ConstSet $s1, ConstSet $s2);\n// fills a set with values and returns it\nfunction fill(Set $s1, $values);\n```\n\nIn addition to the functional methods, there is an OO interface like so\n\n```php\n\u003c?php\n$s1-\u003eunion($s2)\n    -\u003eintersect($s3)\n    -\u003edifference($s4)\n    -\u003eequals($s5);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fcoll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Fcoll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fcoll/lists"}