{"id":28060170,"url":"https://github.com/isgj/collection","last_synced_at":"2026-03-02T22:31:36.096Z","repository":{"id":39746608,"uuid":"471960253","full_name":"isgj/collection","owner":"isgj","description":"Generic data structures in Go","archived":false,"fork":false,"pushed_at":"2022-05-26T14:30:22.000Z","size":45,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T23:43:58.038Z","etag":null,"topics":["data-structures","go","golang","hacktoberfest","iterator","lazy-iterator"],"latest_commit_sha":null,"homepage":"","language":"Go","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/isgj.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":"2022-03-20T11:33:29.000Z","updated_at":"2022-10-07T14:20:16.000Z","dependencies_parsed_at":"2022-09-20T10:14:47.701Z","dependency_job_id":null,"html_url":"https://github.com/isgj/collection","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/isgj/collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isgj%2Fcollection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isgj%2Fcollection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isgj%2Fcollection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isgj%2Fcollection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isgj","download_url":"https://codeload.github.com/isgj/collection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isgj%2Fcollection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273218422,"owners_count":25065913,"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-09-01T02:00:09.058Z","response_time":120,"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":["data-structures","go","golang","hacktoberfest","iterator","lazy-iterator"],"created_at":"2025-05-12T08:39:33.603Z","updated_at":"2026-03-02T22:31:31.065Z","avatar_url":"https://github.com/isgj.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/isgj/collection.svg)](https://pkg.go.dev/github.com/isgj/collection)\n\n# collection\n\nGeneric go structures\n\n## Install\n\n```\ngo get github.com/isgj/collection\n```\n\n## Usage\n\n[collection.Vec[T]](https://pkg.go.dev/github.com/isgj/collection#Vec) implemented as a native go slice `[]T`. Because of this, other than the few currently\nimplemented methods you can use `Vec` also as a regular slice.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/isgj/collection\"\n)\n\nfunc main() {\n\tstrings := collection.Vec[string]{\"str1\", \"str2\"}\n\n\tfor i := 3; i \u003c 6; i++ {\n\t\tstrings = append(strings, fmt.Sprintf(\"str%d\", i))\n\t}\n\n\tsliced := strings[2:4]\n\tindexed := strings[0]\n\tfmt.Printf(\"len=%d, cap=%d, indexed=%s, sliced=%v\\n\", len(strings), cap(strings), indexed, sliced)\n}\n// Output:\n// len=5, cap=8, indexed=str1, sliced=[str3 str4]\n```\n\nThe most noticable method of `Vec` is `Iter` (or `ReverseIter`) which returns a lazy iterator over the\nelements of the slice. Check below.\n\n---\n\n[collection.Iterator[T]](https://pkg.go.dev/github.com/isgj/collection#Iterator) is a lazy iterator over a list of values of type `T`.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/isgj/collection\"\n)\n\nfunc main() {\n\tfirst_slice := collection.Vec[int]{1, 2, 3, 4, 5}\n\tsecond_slice := collection.Vec[int]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14}\n\n\tresult := first_slice.\n\t\tIter().\n\t\tFollowedBy(second_slice.ReverseIter()).\n\t\tFilter(func(item int) bool {\n\t\t\tfmt.Printf(\"will test item: %2d\\n\", item)\n\t\t\treturn item%2 == 0\n\t\t}).\n\t\tSkip(2).\n\t\tTake(3).\n\t\tCollect()\n\n\tfmt.Printf(\"len=%d, cap=%d, vec=%v\\n\", result.Len(), result.Cap(), result)\n}\n// Output:\n// will test item:  1\n// will test item:  2\n// will test item:  3\n// will test item:  4\n// will test item:  5\n// will test item: 14\n// will test item: 12\n// will test item: 10\n// len=3, cap=4, vec=[14 12 10]\n```\n\n\u003e To note: because the iterator is lazy the test of `Filter` is not called on each element, but only as much as needed (no wasted calls).\n\u003e At the end you need to call `Collect` to get back a slice. If `Collect` is not called nothing gets executed.\n\n---\n\n[collection.Map](https://pkg.go.dev/github.com/isgj/collection#Map)\n\n[collection.Set](https://pkg.go.dev/github.com/isgj/collection#Set)\n\n[collection.DLList](https://pkg.go.dev/github.com/isgj/collection#DLList)\n\n[collection.LRUCache](https://pkg.go.dev/github.com/isgj/collection#LRUCache)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisgj%2Fcollection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisgj%2Fcollection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisgj%2Fcollection/lists"}