{"id":36873384,"url":"https://github.com/xfali/stream","last_synced_at":"2026-01-12T15:03:50.081Z","repository":{"id":57530943,"uuid":"270292229","full_name":"xfali/stream","owner":"xfali","description":"A sequence of data values supporting sequential aggregate operations.","archived":false,"fork":false,"pushed_at":"2021-05-26T15:03:11.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-27T22:48:23.745Z","etag":null,"topics":["functional-programming","slice","stream"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xfali.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}},"created_at":"2020-06-07T12:00:10.000Z","updated_at":"2021-05-26T14:50:04.000Z","dependencies_parsed_at":"2022-09-05T10:01:32.069Z","dependency_job_id":null,"html_url":"https://github.com/xfali/stream","commit_stats":null,"previous_names":[],"tags_count":5,"template":null,"template_full_name":null,"purl":"pkg:github/xfali/stream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fstream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fstream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fstream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fstream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xfali","download_url":"https://codeload.github.com/xfali/stream/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fstream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28340416,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["functional-programming","slice","stream"],"created_at":"2026-01-12T15:03:46.912Z","updated_at":"2026-01-12T15:03:50.075Z","avatar_url":"https://github.com/xfali.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stream\n\n[![Build status](https://ci.appveyor.com/api/projects/status/naq9w2g2ohvd4bup?svg=true)](https://ci.appveyor.com/project/xfali/stream)\n[![Go Report Card](https://goreportcard.com/badge/github.com/xfali/stream)](https://goreportcard.com/report/github.com/xfali/stream)\n\nstream是一个支持多种聚合操作的数据序列，支持转化处理的数据有：\n|  类型   | 说明  |\n|  :----  | :----  |\n| slice  | go切片 |\n| list  | go list.List |\n\n支持的方法如下：\n|  方法   | 说明  |\n|  :----  | :----  |\n| Count  | 获得元素的总数 |\n| FindFirst  | 获得第一个元素 |\n| FindLast  | 获得最后一个元素 |\n| FindAny  | 获得一个随机元素 |\n| Filter  | 过滤元素，返回一个包括所有符合过滤条件的元素的流 |\n| Limit  | 返回一个不超过给定长度的流 |\n| Skip  | 返回一个扔掉了前n个元素的流 |\n| Distinct  | 返回一个去重的stream |\n| Sort  | 返回一个排序后的stream |\n| FlatMap  | 映射并扁平化为一个stream |\n| Map  | 由一个类型映射到另一个类型 |\n| Foreach  | 迭代流中所有数据 |\n| Peek  | 获取中间计算的值，主要用于调试 |\n| AnyMatch  | 任意匹配一个则返回true，否则返回false |\n| AllMatch  | 完全匹配返回true，否则返回false |\n| Reduce  | 对stream中元素进行聚合求值 |\n| Collect  | 获得slice |\n\n## 惰性求值\nstream的实现使用惰性求值（Lazy Evaluation）的计算方式以获取更高的性能。\n\n## 安装\n```\ngo get github.com/xfali/stream\n```\n\n## 使用\nslice例子：\n```\ntestSlice := []string{\"0,1,3,2,2,4\", \"5,8,7,6,7,9\"}\nstream.Slice(testSlice).FlatMap(func(s string) []int {\n    return stream.Slice(strings.Split(s, \",\")).Map(func(s string) int {\n        i, _ := strconv.Atoi(s)\n        return i\n    }).Collect().([]int)\n}).Filter(func(i int) bool {\n    return i != 5\n}).Sort(func(a, b int) int {\n    return a - b\n}).Distinct(func(a, b int) bool {\n    return a == b\n}).Map(func(i int) string {\n    return strconv.Itoa(i)\n}).Foreach(func(s string) {\n    t.Log(s)\n})\n```\nlist例子：\n```\ntestList := list.New()\ntestList.PushBack(\"0,1,3,2,2,4\")\ntestList.PushBack(\"5,8,7,6,7,9\")\nstream.List(testList).FlatMap(func(s string) []int {\n    return stream.Slice(strings.Split(s, \",\")).Map(func(s string) int {\n        i, _ := strconv.Atoi(s)\n        return i\n    }).Collect().([]int)\n}).Filter(func(i int) bool {\n    return i != 5\n}).Sort(func(a, b int) int {\n    return a - b\n}).Distinct(func(a, b int) bool {\n    return a == b\n}).Map(func(i int) string {\n    return strconv.Itoa(i)\n}).Foreach(func(s string) {\n    t.Log(s)\n})\n```\n\n## collector\nstream可以通过collect支持更多的操作，内置的操作有：\n|  collector   | 说明  |\n|  :----  | :----  |\n| collector.ToSlice  | 收集为slice |\n| collector.ToList  | 收集为*list.List |\n| collector.ToMap  | 收集为map[KEY]VALUE |\n| collector.GroupBy  | 分组收集为map[KEY][]VALUE |\n\n用法举例:\n```\ns := stream.Slice([]{1, 2, 3, 4, 5}).Filter(func(i int) bool {\n\t\treturn i != 3\n\t}).Collect(collector.ToList()).(*list.List)\n\ne := s.Front()\nfor e != nil {\n    if e.Value.(int) == 3 {\n        t.Fatal(\"cannot be 3\")\n    } else {\n        t.Log(e.Value)\n    }\n    e = e.Next()\n}\n```\n更多用法参考[test](test/stream_test.go)\n\n## 未完成项\n* 并行处理\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfali%2Fstream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxfali%2Fstream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfali%2Fstream/lists"}