{"id":15394183,"url":"https://github.com/xyproto/slice","last_synced_at":"2025-04-15T23:52:37.847Z","repository":{"id":249556793,"uuid":"831840581","full_name":"xyproto/slice","owner":"xyproto","description":":scissors: The missing standard library for slices?","archived":false,"fork":false,"pushed_at":"2024-07-24T06:28:28.000Z","size":1442,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T03:02:06.905Z","etag":null,"topics":["go","slice"],"latest_commit_sha":null,"homepage":"","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/xyproto.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":"2024-07-21T18:59:16.000Z","updated_at":"2024-07-27T18:19:07.000Z","dependencies_parsed_at":"2024-07-26T20:03:59.422Z","dependency_job_id":null,"html_url":"https://github.com/xyproto/slice","commit_stats":{"total_commits":44,"total_committers":2,"mean_commits":22.0,"dds":"0.20454545454545459","last_synced_commit":"1abcad2e6120607e9ec74cacfb445f2a0b28aae8"},"previous_names":["xyproto/missingstdlib"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fslice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fslice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fslice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fslice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyproto","download_url":"https://codeload.github.com/xyproto/slice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173061,"owners_count":21224481,"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":["go","slice"],"created_at":"2024-10-01T15:22:10.826Z","updated_at":"2025-04-15T23:52:37.824Z","avatar_url":"https://github.com/xyproto.png","language":"Go","readme":"# Slice\n\n\u003c!--\u003cimg alt=\"Slice logo\" src=\"img/logo.png\" width=192 align=right\u003e--\u003e\n\n`slice` is a Go package that provides a collection of utility functions that are often needed but missing from the Go standard library. This package includes functions for manipulating slices, such as reversing, shuffling, finding unique elements, and more.\n\n## Installation\n\nTo install the package, run:\n\n```sh\ngo get github.com/xyproto/slice\n```\n\n## Usage\n\nHere are some examples of how to use the functions provided by `slice`.\n\n### Reverse\n\nCreates and returns a new slice that is the reverse of the input slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\nfmt.Println(slice.Reverse([]int{1, 2, 3, 4, 5})) // Output: [5 4 3 2 1]\n```\n\n### ReverseInPlace\n\nReverses a slice in-place.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 4, 5}\nslice.ReverseInPlace(arr)\nfmt.Println(arr) // Output: [5 4 3 2 1]\n```\n\n### ReplaceFirst\n\nReplaces the first occurrence of `needle` with `replacement` in a slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 1, 4}\nfmt.Println(slice.ReplaceFirst(arr, 1, 9)) // Output: [9 2 3 1 4]\n```\n\n### ReplaceLast\n\nReplaces the last occurrence of `needle` with `replacement` in a slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 1, 4}\nfmt.Println(slice.ReplaceLast(arr, 1, 9)) // Output: [1 2 3 9 4]\n```\n\n### Partition\n\nPartitions a slice into two slices based on a predicate function.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 4, 5}\neven, odd := slice.Partition(arr, func(n int) bool { return n%2 == 0 })\nfmt.Println(even, odd) // Output: [2 4] [1 3 5]\n```\n\n### Intersection\n\nReturns the intersection of two slices.\n\n```go\nimport \"github.com/xyproto/slice\"\n\na := []int{1, 2, 3, 4}\nb := []int{3, 4, 5, 6}\nfmt.Println(slice.Intersection(a, b)) // Output: [3 4]\n```\n\n### Difference\n\nReturns the difference between two slices.\n\n```go\nimport \"github.com/xyproto/slice\"\n\na := []int{1, 2, 3, 4}\nb := []int{3, 4, 5, 6}\nfmt.Println(slice.Difference(a, b)) // Output: [1 2]\n```\n\n### Flatten\n\nFlattens a nested slice into a single-level slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\nnested := [][]int{{1, 2}, {3, 4}, {5, 6}}\nfmt.Println(slice.Flatten(nested)) // Output: [1 2 3 4 5 6]\n```\n\n### Unique\n\nRemoves duplicate elements from a slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 2, 3, 4, 4, 5}\nfmt.Println(slice.Unique(arr)) // Output: [1 2 3 4 5]\n```\n\n### Shuffle\n\nRandomly shuffles the elements of a slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 4, 5}\nslice.Shuffle(arr)\nfmt.Println(arr) // Output: [3 5 4 1 2] (example, actual output may vary)\n```\n\n### Zip\n\nCombines multiple slices into a slice of tuples.\n\n```go\nimport \"github.com/xyproto/slice\"\n\na := []int{1, 2, 3}\nb := []string{\"a\", \"b\", \"c\"}\nfmt.Println(slice.Zip(a, b)) // Output: [{1 a} {2 b} {3 c}]\n```\n\n### Contains\n\nChecks if a slice contains a specific element.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 4, 5}\nfmt.Println(slice.Contains(arr, 3)) // Output: true\n```\n\n### Filter\n\nFilters a slice based on a predicate function.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 4, 5}\neven := slice.Filter(arr, func(n int) bool { return n%2 == 0 })\nfmt.Println(even) // Output: [2 4]\n```\n\n### Map\n\nApplies a function to each element in a slice and returns a new slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\nstrArr := []string{\"hello\", \"world\"}\nupperStrArr := slice.Map(strArr, strings.ToUpper)\nfmt.Println(upperStrArr) // Output: [HELLO WORLD]\n```\n\n### Reduce\n\nReduces a slice to a single value using a reduction function.\n\n```go\nimport \"github.com/xyproto/slice\"\n\narr := []int{1, 2, 3, 4, 5}\nsum := slice.Reduce(arr, 0, func(acc, n int) int { return acc + n })\nfmt.Println(sum) // Output: 15\n```\n\n### Capitalize\n\nCapitalizes the first letter of a slice of runes and returns a new slice.\n\n```go\nimport \"github.com/xyproto/slice\"\n\nfmt.Println(string(slice.Capitalize([]rune(\"hello world\")))) // Output: Hello world\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the BSD-3 License - see the [LICENSE](LICENSE) file for details.\n\n## Version\n\n1.0.0\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fslice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyproto%2Fslice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fslice/lists"}