{"id":19954493,"url":"https://github.com/isaccanedo/go-itertools","last_synced_at":"2025-03-01T15:23:59.380Z","repository":{"id":236042117,"uuid":"791784674","full_name":"isaccanedo/go-itertools","owner":"isaccanedo","description":":rotating_light: Combinations and permutations generator in Go, in a similar way to python itertools","archived":false,"fork":false,"pushed_at":"2024-04-26T15:53:24.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T17:03:43.525Z","etag":null,"topics":["combina","combinations","go","golang","permutation","python"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isaccanedo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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":"2024-04-25T11:14:49.000Z","updated_at":"2024-06-19T07:41:39.055Z","dependencies_parsed_at":"2024-06-19T07:41:38.307Z","dependency_job_id":"3a8bb677-3eee-4da0-b0ad-f264599088cf","html_url":"https://github.com/isaccanedo/go-itertools","commit_stats":null,"previous_names":["isaccanedo/go-itertools"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaccanedo%2Fgo-itertools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaccanedo%2Fgo-itertools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaccanedo%2Fgo-itertools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaccanedo%2Fgo-itertools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isaccanedo","download_url":"https://codeload.github.com/isaccanedo/go-itertools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241383187,"owners_count":19954099,"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":["combina","combinations","go","golang","permutation","python"],"created_at":"2024-11-13T01:20:42.695Z","updated_at":"2025-03-01T15:23:59.359Z","avatar_url":"https://github.com/isaccanedo.png","language":"Go","readme":"# itertools\n\nItertools é um kit de ferramentas para gerar combinações e permutações de go slices. Funciona de forma semelhante ao python itertools.\n\n## Installation\n\n    go get -u github.com/isaccanedo/go-itertools\n\n## Usage (Examples)\nAfter installation the package has to be imported.\n```go\nimport \"github.com/isaccanedo/go-itertools\"\n```\n\n###Generating combinations\n*Slices of integers*\n```go\n// combinations of r = 3 elements chosen from iterable\nr := 3\niterable := []int{1, 2, 3, 4 }\n\nfor v := range CombinationsInt(iterable, r) {\n      fmt.Println(v)\n```\noutput:\n```\n[1 2 3]\n[1 2 4]\n[1 3 4]\n[2 3 4]\n```\n*Slices of strings*\n```go\n// combinations of r = 3 elements chosen from iterable\nr := 3\niterable := []string{\"A\", \"B\", \"C\", \"D\"}\n\nfor v := range CombinationsStr(iterable, r) {\n      fmt.Println(v)\n```\noutput:\n```\n[A B C]\n[A B D]\n[A C D]\n[B C D]\n```\n*Custom type List*\n\nNotice you have to use the right function depending of the type of the slice. For a more general case the user could define a custom type List as follows:\n```go\ntype List []interface{}\n```\nThen can create a list of heterogeneous types and follow the same procedure. In this case CombinationsList has to be used.\n\n```go\nr := 3\nmyList := List{1, \"B\", 3, 3.14}\n\nfor v := range CombinationsList(myList, r) {\n      fmt.Println(v)\n```\noutput:\n```\n[1 B 3]\n[1 B 3.14]\n[1 3 3.14]\n[B 3 3.14]\n```\n\n###Generating permutations\n*Slices of integers*\n\nIf the number (r) of chosen element is equal to the length of the _iterable_, then we will obtain the r-factorial permutations\n```go\n// permutations of r = 3 elements chosen from iterable with length 3\nr := 3\niterable := []int{1, 2, 3}\n\nfor v := range PermutationsInt(iterable, r) {\n      fmt.Println(v)\n```\noutput:\n```\n[1 2 3]\n[1 3 2]\n[2 1 3]\n[2 3 1]\n[3 1 2]\n[3 2 1]\n```\n\nOn the other hand we can chose less than len(iterable) elements\n```go\n// permutations of r = 3 elements chosen from a iterable of length 4\nr := 3\niterable := []int{1, 2, 3, 4}\n\nfor v := range CombinationsInt(iterable, r) {\n      fmt.Println(v)\n```\noutput:\n```\n[1 2 3]\n[1 3 2]\n[2 1 3]\n[2 3 1]\n[3 1 2]\n[3 2 1]\n[1 2 4]\n[1 4 2]\n[2 1 4]\n[2 4 1]\n[4 1 2]\n[4 2 1]\n[1 3 4]\n[1 4 3]\n[3 1 4]\n[3 4 1]\n[4 1 3]\n[4 3 1]\n[2 3 4]\n[2 4 3]\n[3 2 4]\n[3 4 2]\n[4 2 3]\n[4 3 2]\n```\n\n*Slices of strings*\n\nSame idea, just use the function PermutationsStr\n\n*Custom type List*\n\nSame as in combinations, fist define the new type List (see above) and then use PermutationsList.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisaccanedo%2Fgo-itertools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisaccanedo%2Fgo-itertools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisaccanedo%2Fgo-itertools/lists"}