mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 01:02:28 +08:00
feat:addFindLast for stream (#95)
Co-authored-by: sunyaoyao <sunyaoyao@kezaihui.com>
This commit is contained in:
@@ -295,6 +295,18 @@ func (s stream[T]) FindFirst() (T, bool) {
|
||||
return s.source[0], true
|
||||
}
|
||||
|
||||
// FindLast returns the last element of this stream and true, or zero value and false if the stream is empty.
|
||||
// Play: https://go.dev/play/p/9xEf0-6C1e3
|
||||
func (s stream[T]) FindLast() (T, bool) {
|
||||
var result T
|
||||
|
||||
if s.source == nil || len(s.source) == 0 {
|
||||
return result, false
|
||||
}
|
||||
|
||||
return s.source[len(s.source)-1], true
|
||||
}
|
||||
|
||||
// Reverse returns a stream whose elements are reverse order of given stream.
|
||||
// Play: https://go.dev/play/p/A8_zkJnLHm4
|
||||
func (s stream[T]) Reverse() stream[T] {
|
||||
|
||||
Reference in New Issue
Block a user