{"id":27203208,"url":"https://github.com/dzherb/go-itertools","last_synced_at":"2025-10-30T03:09:48.322Z","repository":{"id":285634609,"uuid":"958767750","full_name":"dzherb/go-itertools","owner":"dzherb","description":"Miscellaneous utils for iteration","archived":false,"fork":false,"pushed_at":"2025-04-09T20:50:04.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-17T13:10:14.190Z","etag":null,"topics":["functional","go","golang","iteration","itertools","stream"],"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/dzherb.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":"2025-04-01T18:20:40.000Z","updated_at":"2025-05-22T11:18:27.000Z","dependencies_parsed_at":"2025-04-01T21:35:27.774Z","dependency_job_id":"65f28c95-506a-473b-a125-d406052219b1","html_url":"https://github.com/dzherb/go-itertools","commit_stats":null,"previous_names":["dzherb/go-itertools"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dzherb/go-itertools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dzherb%2Fgo-itertools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dzherb%2Fgo-itertools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dzherb%2Fgo-itertools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dzherb%2Fgo-itertools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dzherb","download_url":"https://codeload.github.com/dzherb/go-itertools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dzherb%2Fgo-itertools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275998868,"owners_count":25567391,"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-19T02:00:09.700Z","response_time":108,"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":["functional","go","golang","iteration","itertools","stream"],"created_at":"2025-04-09T22:29:07.923Z","updated_at":"2025-09-20T09:34:03.692Z","avatar_url":"https://github.com/dzherb.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Miscellaneous utils for iteration\n[![Go Reference](https://pkg.go.dev/badge/github.com/dzherb/go-itertools.svg)](https://pkg.go.dev/github.com/dzherb/go-itertools)\n\n\n`go-itertools` is a versatile library inspired by Python's [itertools](https://docs.python.org/3/library/itertools.html), designed to provide elegant and flexible utilities for working with sequences in Go. It offers a wide variety of functions to help you manipulate, combine, and transform iterators in a simple and efficient way.\n\n## Why this is a useful tool\n\nGo's standard library provides some built-in iteration capabilities, but working with sequences can become cumbersome for more advanced operations. `go-itertools` bridges this gap by offering powerful tools that allow you to write cleaner and more expressive code, especially when dealing with complex sequences.\n\nThis library is beneficial in scenarios where you need to:\n\n- Combine multiple sequences in a memory-efficient manner (e.g., chaining or zipping sequences).\n- Create infinite or cyclic sequences.\n- Apply transformations or filters on data with minimal overhead.\n- Write clean and readable code that avoids excessive boilerplate.\n\n### Go and Custom Iterators\n\nStarting from Go 1.23, the language introduced the `iter.Seq` interface, which makes it easy to create [custom iterators](https://go.dev/blog/range-functions) that can be used with Go's `range` loop. This powerful feature allows developers to define their own iteration logic while still leveraging Go's native iteration capabilities. By using type parameters (generics) and the `iter.Seq` interface, we can write reusable and type-safe code that works with sequences of any type. This approach is the foundation of `go-itertools`, enabling more elegant and flexible ways to work with iterators in Go.\n\n---\n\n## Examples\n\nHere are a couple of examples showing how you can use `go-itertools` to work with sequences.\n\n### Basic Iteration with Itertools\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tit \"github.com/dzherb/go-itertools\"\n)\n\nfunc main() {\n\tseq1 := it.Repeat(\"hi\", 3)\n\tseq2 := it.Count(1, 1)\n\n\tfor k, v := range it.Zip(seq1, seq2) {\n\t\tfmt.Println(k, v) // hi 1, hi 2, hi 3\n\t}\n\n\tseq3 := it.FromElements(10, 20, 30)\n\tseq4 := it.FromElements(40, 50)\n\n\tfor s := range it.Chain(seq3, seq4) {\n\t\tfmt.Println(s) // 10, 20, 30, 40, 50\n\t}\n}\n```\n\nIn this example:\n- `Repeat` creates a sequence repeating the value `\"hi\"` three times.\n- `Count` generates a sequence of numbers starting at 1 and incrementing by 1.\n- `Zip` combines two sequences element by element.\n- `Chain` concatenates multiple sequences into a single one.\n\n### Stream API\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tit \"github.com/dzherb/go-itertools\"\n\t\"github.com/dzherb/go-itertools/stream\"\n)\n\nfunc main() {\n\tseq := it.Cycle(it.FromElements(1, 2, 3))\n\n\tst := stream.FromIterator(seq).\n\t\tFilter(func(i int) bool { return i != 2 }).\n\t\tMap(func(i int) int { return i * 2 }).\n\t\tTake(6)\n\n\tfor s := range st {\n\t\tfmt.Println(s) // 2, 6, 2, 6, 2, 6\n\t}\n}\n```\n\nIn this example, the `stream` API is used to create a pipeline that:\n- Starts with a cyclic sequence `[1, 2, 3]`.\n- Filters out the value `2`.\n- Maps the remaining values to their doubles.\n- Limits the sequence to the first 6 elements.\n\nThis shows the power of the stream API, which lets you easily chain multiple operations together to create complex transformations in a clear and readable manner.\n\n--- \n\nWith `go-itertools`, you can easily build complex pipelines for processing sequences, making your Go code more refined, modular, and easier to understand. Whether you are working with simple sequences or need to create intricate transformations, this library provides all the tools you need.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdzherb%2Fgo-itertools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdzherb%2Fgo-itertools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdzherb%2Fgo-itertools/lists"}