{"id":13786658,"url":"https://github.com/leaanthony/slicer","last_synced_at":"2025-07-10T19:03:18.820Z","repository":{"id":43613015,"uuid":"165034725","full_name":"leaanthony/slicer","owner":"leaanthony","description":"Utility class for handling slices","archived":false,"fork":false,"pushed_at":"2021-08-08T01:34:54.000Z","size":109,"stargazers_count":46,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T02:53:30.087Z","etag":null,"topics":["go","go-library","golang","library","slices","utilities"],"latest_commit_sha":null,"homepage":null,"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/leaanthony.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-10T09:55:25.000Z","updated_at":"2024-10-15T09:35:42.000Z","dependencies_parsed_at":"2022-09-26T17:41:16.769Z","dependency_job_id":null,"html_url":"https://github.com/leaanthony/slicer","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/leaanthony/slicer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaanthony%2Fslicer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaanthony%2Fslicer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaanthony%2Fslicer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaanthony%2Fslicer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leaanthony","download_url":"https://codeload.github.com/leaanthony/slicer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leaanthony%2Fslicer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264638007,"owners_count":23642093,"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","go-library","golang","library","slices","utilities"],"created_at":"2024-08-03T19:01:27.314Z","updated_at":"2025-07-10T19:03:18.541Z","avatar_url":"https://github.com/leaanthony.png","language":"Go","funding_links":[],"categories":["公用事业公司","Utilities","工具库","工具库`可以提升效率的通用代码库和工具`","Utility"],"sub_categories":["实用程序/Miscellaneous","HTTP Clients","查询语","Utility/Miscellaneous","Fail injection"],"readme":"\n\u003cdiv style=\"text-align:center; width:400px\"\u003e\n  \u003cimg src=\"logo.png\"/\u003e\n  Utility class for handling slices.\n\u003c/div\u003e\n\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/leaanthony/slicer)](https://goreportcard.com/report/github.com/leaanthony/slicer)  [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/leaanthony/slicer) [![CodeFactor](https://www.codefactor.io/repository/github/leaanthony/slicer/badge)](https://www.codefactor.io/repository/github/leaanthony/slicer) [![codecov](https://codecov.io/gh/leaanthony/slicer/branch/master/graph/badge.svg)](https://codecov.io/gh/leaanthony/slicer) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)  \n\n\n\n\n\n## Install\n\n`go get -u github.com/leaanthony/slicer`\n\n## Quick Start\n\n```\n  import \"github.com/leaanthony/slicer\"\n\n  func test() {\n    s := slicer.String()\n    s.Add(\"one\")\n    s.Add(\"two\")\n    s.AddSlice([]string{\"three\",\"four\"})\n    fmt.Printf(\"My slice = %+v\\n\", s.AsSlice())\n    \n    t := slicer.String()\n    t.Add(\"zero\")\n    t.AddSlicer(s)\n    fmt.Printf(\"My slice = %+v\\n\", t.AsSlice())\n  }\n```\n\n## Available slicers\n\n- Int\n- Int8\n- Int16\n- Int32\n- Int64  \n- UInt\n- UInt8\n- UInt16\n- UInt32\n- UInt64\n- Float32\n- Float64\n- String\n- Bool\n- Interface\n  \n## API\n\n### Construction\n\nCreate new Slicers by calling one of the following functions:\n  - Int()\n  - Int8()\n  - Int16()\n  - Int32()\n  - Int64()\n  - Float32()\n  - Float64()\n  - String()\n  - Bool()\n  - Interface()\n\n```\n  s := slicer.String()\n```\n\nIf you wish to convert an existing slice to a Slicer, you may pass it in during creation:\n\n```\n  values := []string{\"one\", \"two\", \"three\"}\n  s := slicer.String(values)\n```\n\n### Add \n\nAdds a value to the slice.\n\n```\n  values := []string{\"one\", \"two\", \"three\"}\n  s := slicer.String(values)\n  s.Add(\"four\")\n```\n\n### AddUnique\n\nAdds a value to the slice if it doesn't already contain it.\n\n```\n  values := []string{\"one\", \"two\", \"three\", \"one\", \"two\", \"three\"}\n  s := slicer.String(values)\n  result := s.Join(\",\")\n  // result is \"one,two,three\"\n```\n### AddSlice\n\nAdds an existing slice of values to a slicer\n\n```\n  s := slicer.String([]string{\"one\"})\n  s.AddSlice([]string{\"two\"})\n```\n\n### AsSlice\n\nReturns a regular slice from the slicer.\n\n```\n  s := slicer.String([]string{\"one\"})\n  for _, value := range s.AsSlice() {\n    ...\n  }\n```\n\n### AddSlicer\n\nAdds an existing slicer of values to another slicer\n\n```\n  a := slicer.String([]string{\"one\"})\n  b := slicer.String([]string{\"two\"})\n  a.AddSlicer(b)\n```\n\n### Filter\n\nFilter the values of a slicer based on the result of calling the given function with each value of the slice. If it returns true, the value is added to the result.\n\n```\n  a := slicer.Int([]int{1,5,7,9,6,3,1,9,1})\n  result := a.Filter(func(v int) bool {\n    return v \u003e 5\n  })\n  // result is []int{7,9,9}\n  \n```\n\n### Each \n\nEach iterates over all the values of a slicer, passing them in as paramter to a function\n\n```\n  a := slicer.Int([]int{1,5,7,9,6,3,1,9,1})\n  result := 0\n  a.Each(func(v int) {\n    result += v\n  })\n  // result is 42\n```\n\n### Contains\n\nContains returns true if the slicer contains the given value\n\n```\n  a := slicer.Int([]int{1,5,7,9,6,3,1,9,1})\n  result := a.Contains(9)\n  // result is True\n```\n\n### Join\n\nReturns a string with the slicer elements separated by the given separator\n\n```\n  a := slicer.String([]string{\"one\", \"two\", \"three\"})\n  result := a.Join(\",\")\n  // result is \"one,two,three\"\n```\n### Length\n\nReturns the length of the slice\n\n```\n  a := slicer.String([]string{\"one\", \"two\", \"three\"})\n  result := a.Length()\n  // result is 3\n```\n\n### Clear\n\nClears all elements from the current slice\n\n```\n  a := slicer.String([]string{\"one\", \"two\", \"three\"})\n  a.Clear()\n  // a.Length() == 0\n```\n\n### Sort\n\nSorts the elements of a slice\nNot supported by: InterfaceSlicer, BoolSlicer\n\n```\n  a := slicer.Int([]int{5,3,4,1,2})\n  a.Sort()\n  // a is []int{1,2,3,4,5}\n```\n\n### Deduplicate\n\nDeduplicate removes all duplicates within a slice.\n\n```\n  a := slicer.Int([]int{5,3,5,1,3})\n  a.Deduplicate()\n  // a is []int{5,3,1}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleaanthony%2Fslicer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleaanthony%2Fslicer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleaanthony%2Fslicer/lists"}