diff --git a/docs/stream.md b/docs/stream.md index c993bb3..20ee721 100644 --- a/docs/stream.md +++ b/docs/stream.md @@ -40,6 +40,7 @@ import ( - [ForEach](#ForEach) - [Reduce](#Reduce) - [FindFirst](#FindFirst) +- [FindLast](#FindLast) - [Max](#Max) - [Min](#Min) - [AllMatch](#AllMatch) @@ -667,6 +668,38 @@ func main() { } ``` +### FindLast + +
Returns the last element of this stream and true, or zero value and false if the stream is empty.
+ +Signature: + +```go +func (s stream[T]) FindLast() (T, bool) +``` + +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/stream" +) + +func main() { + original := FromSlice([]int{3, 2, 1}) + + result, ok := original.FindLast() + + fmt.Println(result) + fmt.Println(ok) + + // Output: + // 1 + // true +} +``` + ### MaxReturns the maximum element of this stream according to the provided less function. less fuction: a > b
diff --git a/docs/stream_zh-CN.md b/docs/stream_zh-CN.md index f227704..ad68b5e 100644 --- a/docs/stream_zh-CN.md +++ b/docs/stream_zh-CN.md @@ -40,6 +40,7 @@ import ( - [ForEach](#ForEach) - [Reduce](#Reduce) - [FindFirst](#FindFirst) +- [FindLast](#FindLast) - [Max](#Max) - [Min](#Min) - [AllMatch](#AllMatch) @@ -667,6 +668,38 @@ func main() { } ``` +### FindLast + +返回此stream最后一个元素和true,如果stream为空,则返回零值和false。
+ +函数签名: + +```go +func (s stream[T]) FindLast() (T, bool) +``` + +示例: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/stream" +) + +func main() { + original := FromSlice([]int{3, 2, 1}) + + result, ok := original.FindLast() + + fmt.Println(result) + fmt.Println(ok) + + // Output: + // 1 + // true +} +``` + ### Max根据提供的less函数返回stream的最大元素。less 函数: a > b