From ba02fd4accd47dd12ce6319ebbd0ae10e6409adb Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 22 Sep 2023 10:41:45 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20README=20=E5=A2=9E=E5=8A=A0=E6=B5=81?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 09feead..d9997f0 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,46 @@ func main() { } ``` +### 流操作 +可以通过 `stream` 包快速开启对`切片`和`map`的流式操作,例如: +```go +package main + +import ( + "fmt" + "github.com/kercylan98/minotaur/utils/stream" + "github.com/kercylan98/minotaur/utils/streams" +) + +func main() { + s := stream.WithSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}). + Copy(). + Shuffle(). + Filter(true, func(index int, item int) bool { + return item%2 == 0 + }). + Zoom(20). + Each(true, func(index int, item int) bool { + t.Log(index, item) + return false + }). + Chunk(3). + EachT(func(index int, item stream.Slice[int]) bool { + t.Log(item) + return false + }). + Merge(). + FillBy(func(index int, value int) int { + if value == 0 { + return 999 + } + return value + }) + + fmt.Println(s) +} +``` + ### 持续更新的示例项目 - **[Minotaur-Example](https://github.com/kercylan98/minotaur-example)**