{"id":16610207,"url":"https://github.com/tmr232/go-explore","last_synced_at":"2026-05-01T06:31:23.161Z","repository":{"id":64692289,"uuid":"443144506","full_name":"tmr232/go-explore","owner":"tmr232","description":"My explorations of Go","archived":false,"fork":false,"pushed_at":"2022-01-28T15:00:33.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-18T04:37:41.461Z","etag":null,"topics":["experimental","go","golang","itertools","python"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmr232.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-30T17:40:39.000Z","updated_at":"2022-01-12T17:49:32.000Z","dependencies_parsed_at":"2022-12-14T19:01:20.020Z","dependency_job_id":null,"html_url":"https://github.com/tmr232/go-explore","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tmr232/go-explore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmr232%2Fgo-explore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmr232%2Fgo-explore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmr232%2Fgo-explore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmr232%2Fgo-explore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmr232","download_url":"https://codeload.github.com/tmr232/go-explore/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmr232%2Fgo-explore/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32487300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["experimental","go","golang","itertools","python"],"created_at":"2024-10-12T01:29:32.874Z","updated_at":"2026-05-01T06:31:23.144Z","avatar_url":"https://github.com/tmr232.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-explore\n\nIn this repo I experiment with Golang.\n\nWhile the packages within may be in a usable state,\nthey are still highly experimental and subject to change.\n\n## Itertools\n\nPorting Python's `itertools` module (and a bit more) into Go.\n\nIt is built around the `Iterator[T]` interface: \n\n```go\ntype Iterator[T any] interface {\n\t// Next tries to advance to the next value.\n\t// Returns true if a value exists, false if not.\n\t// Once an iterator returns false to indicate exhaustion,\n\t// it should continue returning false.\n\tNext() bool\n\t// Value returns the current value of the iterator.\n\t// Next() must be called and return true before every call to Value().\n\tValue() T\n}\n```\n\nIteration is fairly straightforward:\n\n```go\nfor iter := Literal(1,2,3); iter.Next(); {\n\tfmt.Println(iter.Value())\n}\n```\n\nWould result in\n\n```text\n1\n2\n3\n```\n\n#### Fibonacci\n\nA simple Fibonacci iterator can be written as follows (`itertools.` remove for brevity):\n\n```go\nfunc Fibonacci() Iterator[int] {\n\ta, b := 1, 1\n\tadvance := func() (bool, int) {\n\t\tretval := a\n\t\ta, b = b, a + b\n\t\treturn true, retval\n\t}\n\treturn FromAdvance(advance)\n}\n```\n\nNote that this iterator is \"infinite\".\nIt does not stop after a set number, but keeps going.\nIf we only want to print the first 10 elements, \nwe can `Take` the first 10 elements and print them:\n\n```go\nForEach(\n    Take(                           // Take the first\n        10,                         // 10 elements\n        Fibonacci(),                // from our Fibonacci sequence\n    ),\n    func(v int) { fmt.Println(v) }, // and print them\n)\n```\n\nResulting in \n```text\n1\n1 \n2 \n3 \n5 \n8 \n13\n21\n34\n55\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmr232%2Fgo-explore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmr232%2Fgo-explore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmr232%2Fgo-explore/lists"}