From 85e28065313fc64856d951c3bbd3c864450952dc Mon Sep 17 00:00:00 2001 From: dudaodong Date: Thu, 18 May 2023 10:21:24 +0800 Subject: [PATCH] doc: add doc for FindLast --- docs/stream.md | 33 +++++++++++++++++++++++++++++++++ docs/stream_zh-CN.md | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) 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 +} +``` + ### Max

Returns 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