{"id":37223979,"url":"https://github.com/jasonbot/chains","last_synced_at":"2026-01-15T01:39:09.306Z","repository":{"id":264409295,"uuid":"893287623","full_name":"jasonbot/chains","owner":"jasonbot","description":"Fun tricks for stream-style programming: the inevitable, sad but logical conclusion of iterators and generics in Go","archived":false,"fork":false,"pushed_at":"2025-09-18T18:11:07.000Z","size":116,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-18T21:10:49.304Z","etag":null,"topics":["functional-programming","golang","iterator","itertools"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/jasonscheirer.com/chains","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasonbot.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-24T02:59:23.000Z","updated_at":"2025-09-18T18:39:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"5030b749-ea09-4e79-9cb8-904e7145543f","html_url":"https://github.com/jasonbot/chains","commit_stats":null,"previous_names":["jasonbot/chains"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/jasonbot/chains","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbot%2Fchains","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbot%2Fchains/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbot%2Fchains/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbot%2Fchains/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasonbot","download_url":"https://codeload.github.com/jasonbot/chains/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbot%2Fchains/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"ssl_error","status_checked_at":"2026-01-15T00:55:20.945Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["functional-programming","golang","iterator","itertools"],"created_at":"2026-01-15T01:39:08.679Z","updated_at":"2026-01-15T01:39:09.297Z","avatar_url":"https://github.com/jasonbot.png","language":"Go","readme":"# Chained Iterators in Go\n\n\u003e [!NOTE]\n\u003e I wrote [a blog post on this library](https://www.jasonscheirer.com/weblog/chains/), which is a nice medium-form introduction to the lib and its motivators/usage.\n\nI haven't done much in Go lately, and I definitely haven't played with generics or iterators yet. Why not do both?\n\nSo now you can do this:\n\n```go\nmyArray := []int{1, 2, 3}\n\nreturnArray := ChainFromSlice(\n    []int{8, 10, 145, 3},\n).Map(\n    func(i int) int {\n        return i * 3\n    },\n).Filter(\n    func(i int) bool {\n        return i%2 == 0\n    },\n).Slice()\n// returnArray == []int{24, 30}\n\n```\n\nThis library is meant to fill a void in some of the niceness I get in Python and Ruby -- you'll note there is a whole subset of [Python's `itertools` library](https://docs.python.org/3/library/itertools.html) here.\n\n## Examples\n\nInteresting examples live in [`cookbook_test`](cookbook_test.go).\n\n## Warts\n\nThe Go templating system is a little limited, so you can't do something like this:\n\n```go\narrayOfStrings := ChainFromSlice(\n    []int{8, 10, 145, 3},\n).Map(\n    // Compiler can't infer you're going from Chain[int] to Chain[string]\n    func(i int) string {\n        return fmt.Sprintf(\"%v\", i)\n    },\n)\n```\n\nThe generic system does not allow for templated methods, so chaining methods and expecting to go from `Chain[T]` to `Chain[V]` isn't possible.\n\nYou need to give the templating system a hint with a junction, telling it there's 2 types involved:\n\n```go\nmapFunc := func(i int) string { return fmt.Sprintf(\"%v\", i) }\narray := []int{1, 2, 3, 4}\n// Converting type in .Map(), so the generic has to be aware of both types\nreturnArray := ChainJunction[int, string](ChainFromSlice(\n    array,\n).Filter(\n    func(i int) bool {\n        return i%2 == 0\n    },\n)).Map(\n    mapFunc,\n).Slice()\n// secondreturnArrayArray == []string{\"2\", \"4\"}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonbot%2Fchains","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonbot%2Fchains","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonbot%2Fchains/lists"}