1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

doc: update stream package document

This commit is contained in:
dudaodong
2023-04-17 13:53:47 +08:00
parent a8a96be21b
commit c3fad62d8c
4 changed files with 193 additions and 25 deletions

View File

@@ -1063,7 +1063,91 @@ import "github.com/duke-git/lancet/v2/slice"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#KeyBy)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#KeyBy)]
[[play](https://go.dev/play/p/uXod2LWD1Kg)] [[play](https://go.dev/play/p/uXod2LWD1Kg)]
### 17. Structs package provides several high level functions to manipulate struct, tag, and field. ### 17. Stream package implements a sequence of elements supporting sequential and operations. this package is an experiment to explore if stream in go can work as the way java does. its function is very limited.
```go
import "github.com/duke-git/lancet/v2/stream"
```
#### Function list:
- **<big>Of</big>** : creates a stream whose elements are the specified values.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Of)]
[[play](https://go.dev/play/p/jI6_iZZuVFE)]
- **<big>FromSlice</big>** : creates a stream from slice.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#FromSlice)]
[[play](https://go.dev/play/p/wywTO0XZtI4)]
- **<big>FromChannel</big>** : creates a stream from channel.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#FromChannel)]
[[play](https://go.dev/play/p/9TZYugGMhXZ)]
- **<big>FromRange</big>** : creates a number stream from start to end. both start and end are included. [start, end]
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#FromRange)]
[[play](https://go.dev/play/p/9Ex1-zcg-B-)]
- **<big>Generate</big>** : creates a stream where each element is generated by the provided generater function.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Generate)]
[[play](https://go.dev/play/p/rkOWL1yA3j9)]
- **<big>Concat</big>** : creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Concat)]
[[play](https://go.dev/play/p/HM4OlYk_OUC)]
- **<big>Distinct</big>** : creates returns a stream that removes the duplicated items.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Distinct)]
[[play](https://go.dev/play/p/eGkOSrm64cB)]
- **<big>Filter</big>** : returns a stream consisting of the elements of this stream that match the given predicate.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Filter)]
[[play](https://go.dev/play/p/MFlSANo-buc)]
- **<big>Map</big>** : returns a stream consisting of the elements of this stream that apply the given function to elements of stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Map)]
[[play](https://go.dev/play/p/OtNQUImdYko)]
- **<big>Peek</big>** : returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Peek)]
[[play](https://go.dev/play/p/u1VNzHs6cb2)]
- **<big>Skip</big>** : returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Skip)]
[[play](https://go.dev/play/p/fNdHbqjahum)]
- **<big>Limit</big>** : returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Limit)]
[[play](https://go.dev/play/p/qsO4aniDcGf)]
- **<big>Reverse</big>** : returns a stream whose elements are reverse order of given stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Reverse)]
[[play](https://go.dev/play/p/A8_zkJnLHm4)]
- **<big>Range</big>** : returns a stream whose elements are in the range from start(included) to end(excluded) original stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Range)]
[[play](https://go.dev/play/p/indZY5V2f4j)]
- **<big>Sorted</big>** : returns a stream consisting of the elements of this stream, sorted according to the provided less function.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Sorted)]
[[play](https://go.dev/play/p/XXtng5uonFj)]
- **<big>ForEach</big>** : performs an action for each element of this stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#ForEach)]
[[play](https://go.dev/play/p/Dsm0fPqcidk)]
- **<big>Reduce</big>** : performs a reduction on the elements of this stream, using an associative accumulation function, and returns an Optional describing the reduced value, if any.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Reduce)]
[[play](https://go.dev/play/p/6uzZjq_DJLU)]
- **<big>FindFirst</big>** : returns the first element of this stream and true, or zero value and false if the stream is empty.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#FindFirst)]
[[play](https://go.dev/play/p/9xEf0-6C1e3)]
- **<big>Max</big>** : returns the maximum element of this stream according to the provided less function. less fuction: a > b
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Max)]
[[play](https://go.dev/play/p/fm-1KOPtGzn)]
- **<big>Min</big>** : returns the minimum element of this stream according to the provided less function. less fuction: a < b
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Min)]
[[play](https://go.dev/play/p/vZfIDgGNRe_0)]
- **<big>AllMatch</big>** : returns whether all elements of this stream match the provided predicate.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#AllMatch)]
[[play](https://go.dev/play/p/V5TBpVRs-Cx)]
- **<big>AnyMatch</big>** : returns whether any elements of this stream match the provided predicate.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#AnyMatch)]
[[play](https://go.dev/play/p/PTCnWn4OxSn)]
- **<big>NoneMatch</big>** : returns whether no elements of this stream match the provided predicate.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#NoneMatch)]
[[play](https://go.dev/play/p/iWS64pL1oo3)]
- **<big>Count</big>** : returns the count of elements in the stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#Count)]
[[play](https://go.dev/play/p/r3koY6y_Xo-)]
- **<big>ToSlice</big>** : returns the elements in the stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream.md#ToSlice)]
[[play](https://go.dev/play/p/jI6_iZZuVFE)]
### 18. Structs package provides several high level functions to manipulate struct, tag, and field.
```go ```go
import "github.com/duke-git/lancet/v2/structs" import "github.com/duke-git/lancet/v2/structs"
@@ -1096,7 +1180,7 @@ import "github.com/duke-git/lancet/v2/structs"
- **<big>IsSlice</big>** : check if the field is a slice - **<big>IsSlice</big>** : check if the field is a slice
[[doc](https://github.com/duke-git/lancet/blob/main/docs/structs/field.md#IsSlice)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/structs/field.md#IsSlice)]
### 18. Strutil package contains some functions to manipulate string. ### 19. Strutil package contains some functions to manipulate string.
```go ```go
import "github.com/duke-git/lancet/v2/strutil" import "github.com/duke-git/lancet/v2/strutil"
@@ -1176,7 +1260,7 @@ import "github.com/duke-git/lancet/v2/strutil"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#RemoveNonPrintable)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#RemoveNonPrintable)]
[[play](https://go.dev/play/p/og47F5x_jTZ)] [[play](https://go.dev/play/p/og47F5x_jTZ)]
### 19. System package contain some functions about os, runtime, shell command. ### 20. System package contain some functions about os, runtime, shell command.
```go ```go
import "github.com/duke-git/lancet/v2/system" import "github.com/duke-git/lancet/v2/system"
@@ -1212,7 +1296,7 @@ import "github.com/duke-git/lancet/v2/system"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/system.md#GetOsBits)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/system.md#GetOsBits)]
[[play](https://go.dev/play/p/ml-_XH3gJbW)] [[play](https://go.dev/play/p/ml-_XH3gJbW)]
### 20. Validator package contains some functions for data validation. ### 21. Validator package contains some functions for data validation.
```go ```go
import "github.com/duke-git/lancet/v2/validator" import "github.com/duke-git/lancet/v2/validator"
@@ -1317,7 +1401,7 @@ import "github.com/duke-git/lancet/v2/validator"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsPrintable)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsPrintable)]
[[play](https://go.dev/play/p/Pe1FE2gdtTP)] [[play](https://go.dev/play/p/Pe1FE2gdtTP)]
### 21. xerror package implements helpers for errors. ### 22. xerror package implements helpers for errors.
```go ```go
import "github.com/duke-git/lancet/v2/xerror" import "github.com/duke-git/lancet/v2/xerror"

View File

@@ -1062,7 +1062,91 @@ import "github.com/duke-git/lancet/v2/slice"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#KeyBy)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#KeyBy)]
[[play](https://go.dev/play/p/uXod2LWD1Kg)] [[play](https://go.dev/play/p/uXod2LWD1Kg)]
### 17. structs 提供操作 struct, tag, field 的相关函数 ### 17. Stream 流,该包仅验证简单的 stream 实现,功能有限
```go
import "github.com/duke-git/lancet/v2/stream"
```
#### Function list:
- **<big>Of</big>** : 创建元素为指定值的 stream。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Of)]
[[play](https://go.dev/play/p/jI6_iZZuVFE)]
- **<big>FromSlice</big>** : 从切片创建 stream。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#FromSlice)]
[[play](https://go.dev/play/p/wywTO0XZtI4)]
- **<big>FromChannel</big>** : 从通道创建 stream。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#FromChannel)]
[[play](https://go.dev/play/p/9TZYugGMhXZ)]
- **<big>FromRange</big>** : 指定一个数字范围创建 stream, 范围两端点值都包括在内。. [start, end]
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#FromRange)]
[[play](https://go.dev/play/p/9Ex1-zcg-B-)]
- **<big>Generate</big>** : 创建一个 stream其中每个元素都由提供的生成器函数生成。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Generate)]
[[play](https://go.dev/play/p/rkOWL1yA3j9)]
- **<big>Concat</big>** : 创建一个延迟连接 stream其元素是第一个 stream 的所有元素,后跟第二个 stream 的全部元素。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Concat)]
[[play](https://go.dev/play/p/HM4OlYk_OUC)]
- **<big>Distinct</big>** : 创建并返回一个 stream用于删除重复的项。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Distinct)]
[[play](https://go.dev/play/p/eGkOSrm64cB)]
- **<big>Filter</big>** : 返回一个通过判定函数的 stream。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Filter)]
[[play](https://go.dev/play/p/MFlSANo-buc)]
- **<big>Map</big>** : 返回一个 stream该 stream 由将给定函数应用于源 stream 元素的元素组成。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Map)]
[[play](https://go.dev/play/p/OtNQUImdYko)]
- **<big>Peek</big>** : 返回一个由源 stream 的元素组成的 stream并在从生成的 stream 中消耗元素时对每个元素执行所提供的操作。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Peek)]
[[play](https://go.dev/play/p/u1VNzHs6cb2)]
- **<big>Skip</big>** : 在丢弃 stream 的前 n 个元素后,返回由源 stream 的其余元素组成的 stream。如果此 stream 包含的元素少于 n 个,则将返回一个空 stream。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Skip)]
[[play](https://go.dev/play/p/fNdHbqjahum)]
- **<big>Limit</big>** : 返回由源 stream 的元素组成的 stream该 stream 被截断为长度不超过 maxSize。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Limit)]
[[play](https://go.dev/play/p/qsO4aniDcGf)]
- **<big>Reverse</big>** : 返回元素与源 stream 的顺序相反的 stream。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Reverse)]
[[play](https://go.dev/play/p/A8_zkJnLHm4)]
- **<big>Range</big>** : 返回一个 stream该 stream 的元素在从源 stream 的开始(包含)到结束(排除)的范围内。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Range)]
[[play](https://go.dev/play/p/indZY5V2f4j)]
- **<big>Sorted</big>** : 返回一个 stream该 stream 由源 stream 的元素组成,并根据提供的 less 函数进行排序。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Sorted)]
[[play](https://go.dev/play/p/XXtng5uonFj)]
- **<big>ForEach</big>** : 对 stream 的每个元素执行一个操作。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#ForEach)]
[[play](https://go.dev/play/p/Dsm0fPqcidk)]
- **<big>Reduce</big>** : 使用关联累加函数对 stream 的元素执行 reduce 操作,并 reduce 操作结果(如果有)。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Reduce)]
[[play](https://go.dev/play/p/6uzZjq_DJLU)]
- **<big>FindFirst</big>** : 返回此 stream 的第一个元素和 true如果 stream 为空,则返回零值和 false。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#FindFirst)]
[[play](https://go.dev/play/p/9xEf0-6C1e3)]
- **<big>Max</big>** : 根据提供的 less 函数返回 stream 的最大元素。less 函数: a > b
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Max)]
[[play](https://go.dev/play/p/fm-1KOPtGzn)]
- **<big>Min</big>** : 根据提供的 less 函数返回 stream 的最小元素。less 函数: a < b
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Min)]
[[play](https://go.dev/play/p/vZfIDgGNRe_0)]
- **<big>AllMatch</big>** : 判断 stream 的所有元素是否全部匹配指定判定函数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#AllMatch)]
[[play](https://go.dev/play/p/V5TBpVRs-Cx)]
- **<big>AnyMatch</big>** : 判断 stream 是否包含匹配指定判定函数的元素。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#AnyMatch)]
[[play](https://go.dev/play/p/PTCnWn4OxSn)]
- **<big>NoneMatch</big>** : 判断 stream 的元素是否全部不匹配指定的判定函数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#NoneMatch)]
[[play](https://go.dev/play/p/iWS64pL1oo3)]
- **<big>Count</big>** : 返回 stream 中元素的数量。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Count)]
[[play](https://go.dev/play/p/r3koY6y_Xo-)]
- **<big>ToSlice</big>** : 返回 stream 中的元素切片。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#ToSlice)]
[[play](https://go.dev/play/p/jI6_iZZuVFE)]
### 18. structs 提供操作 struct, tag, field 的相关函数。
```go ```go
import "github.com/duke-git/lancet/v2/structs" import "github.com/duke-git/lancet/v2/structs"
@@ -1097,7 +1181,7 @@ import "github.com/duke-git/lancet/v2/structs"
- **<big>IsSlice</big>** : 判断属性是否是切片。 - **<big>IsSlice</big>** : 判断属性是否是切片。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/structs/field_zh-CN.md#IsSlice)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/structs/field_zh-CN.md#IsSlice)]
### 18. strutil 包含字符串处理的相关函数。 ### 19. strutil 包含字符串处理的相关函数。
```go ```go
import "github.com/duke-git/lancet/v2/strutil" import "github.com/duke-git/lancet/v2/strutil"
@@ -1178,7 +1262,7 @@ import "github.com/duke-git/lancet/v2/strutil"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#RemoveNonPrintable)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#RemoveNonPrintable)]
[[play](https://go.dev/play/p/og47F5x_jTZ)] [[play](https://go.dev/play/p/og47F5x_jTZ)]
### 19. system 包含 os, runtime, shell command 的相关函数。 ### 20. system 包含 os, runtime, shell command 的相关函数。
```go ```go
import "github.com/duke-git/lancet/v2/system" import "github.com/duke-git/lancet/v2/system"
@@ -1214,7 +1298,7 @@ import "github.com/duke-git/lancet/v2/system"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/system_zh-CN#GetOsBits)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/system_zh-CN#GetOsBits)]
[[play](https://go.dev/play/p/ml-_XH3gJbW)] [[play](https://go.dev/play/p/ml-_XH3gJbW)]
### 20. validator 验证器包,包含常用字符串格式验证函数。 ### 21. validator 验证器包,包含常用字符串格式验证函数。
```go ```go
import "github.com/duke-git/lancet/v2/validator" import "github.com/duke-git/lancet/v2/validator"
@@ -1319,7 +1403,7 @@ import "github.com/duke-git/lancet/v2/validator"
[[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsPrintable)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsPrintable)]
[[play](https://go.dev/play/p/Pe1FE2gdtTP)] [[play](https://go.dev/play/p/Pe1FE2gdtTP)]
### 21. xerror 包实现一些错误处理函数 ### 22. xerror 包实现一些错误处理函数
```go ```go
import "github.com/duke-git/lancet/v2/xerror" import "github.com/duke-git/lancet/v2/xerror"

View File

@@ -1,6 +1,6 @@
# Strutil # Stream
Stream 实现,该包仅验证简单 go stream 实现,功能有限。 Stream ,该包仅验证简单 stream 实现,功能有限。
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by MIT license // Use of this source code is governed by MIT license
// Package stream implements a sequence of elements supporting sequential and operations. // Package stream implements a sequence of elements supporting sequential and operations.
// this package is an experiment to explore if stream in go can work as the way java does. it's function is very limited. // this package is an experiment to explore if stream in go can work as the way java does. its function is very limited.
package stream package stream
import ( import (