{"id":20295992,"url":"https://github.com/peterq/slice-chain","last_synced_at":"2025-06-20T23:33:17.783Z","repository":{"id":57501070,"uuid":"217493444","full_name":"peterq/slice-chain","owner":"peterq","description":"像 JavaScript 操作数组一样链式操作 golang 的slice","archived":false,"fork":false,"pushed_at":"2021-09-27T02:02:01.000Z","size":17,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T12:23:05.629Z","etag":null,"topics":[],"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/peterq.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":"2019-10-25T08:55:52.000Z","updated_at":"2023-02-12T08:06:17.000Z","dependencies_parsed_at":"2022-09-14T19:41:39.161Z","dependency_job_id":null,"html_url":"https://github.com/peterq/slice-chain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peterq/slice-chain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterq%2Fslice-chain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterq%2Fslice-chain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterq%2Fslice-chain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterq%2Fslice-chain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterq","download_url":"https://codeload.github.com/peterq/slice-chain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterq%2Fslice-chain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261036482,"owners_count":23100930,"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":[],"created_at":"2024-11-14T15:36:54.656Z","updated_at":"2025-06-20T23:33:12.773Z","avatar_url":"https://github.com/peterq.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e chain style operation for golang's slice just like javascript array\n\nsupport operation:\n - Map:\n   - convert slice of any type A to slice of any type B\n - Filter:\n   - delete elements of a slice you do not need\n - Sort:\n   - sort a slice of any type on your rule\n - Find:\n   - find the element in the slice you need\n - Reverse:\n   - reverse the element\n - Reduce:\n   - walk the slice reduce to a single value\n \n\u003e 像 JavaScript 操作数组一样链式操作 golang 的slice\n\n支持的操作:\n - Map:\n   - 从一种类型的切片转换成另一种类型的切片\n - Filter:\n   - 过滤切片中不符合条件的元素, 返回新的切片\n - Sort:\n   - 自定义规则对切片进行排序\n - Find:\n   - 找出切片中符合条件的第一个元素, 返回该元素和该元素的索引\n - Reverse:\n   - 颠倒切片元素先后顺序\n - Reduce:\n   - 遍历数组, 归并成一个值\n\n\neg: run:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/peterq/slice-chain\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tvar a = []string{\"1\", \"2\", \"3\", \"4\", \"5\"}\n\n\tslice_chain.Collect(a).\n\t\tMap(func(s string) int { i, _ := strconv.Atoi(s); return i }).\n\t\tFilter(func(i int) bool { return i%2 == 0 }).\n\t\tMap(func(i int) string { return fmt.Sprintf(\"%d * %d = %d\", i, i, i*i) }).\n\t\tSaveTo(\u0026a)\n\n\tprintln(strings.Join(a, \"\\n\"))\n}\n```\ngot output: \n```\n2 * 2 = 4\n4 * 4 = 16\n```\n\n\u003e more usage you can find in the `chain_test.go` file\n\n\nissue and pr are welcomed ;)\n\nlove golang, love china. may the world peace :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterq%2Fslice-chain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterq%2Fslice-chain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterq%2Fslice-chain/lists"}