1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 15:12:26 +08:00

feat: add IndexOf and LastIndexOf for stream

This commit is contained in:
dudaodong
2024-11-11 10:52:29 +08:00
parent de877e5278
commit f3579fc142
7 changed files with 263 additions and 62 deletions

View File

@@ -384,3 +384,31 @@ func ExampleStream_Count() {
// 3
// 0
}
func ExampleStream_IndexOf() {
s := FromSlice([]int{1, 2, 3, 2})
result1 := s.IndexOf(0, func(a, b int) bool { return a == b })
result2 := s.IndexOf(2, func(a, b int) bool { return a == b })
fmt.Println(result1)
fmt.Println(result2)
// Output:
// -1
// 1
}
func ExampleStream_LastIndexOf() {
s := FromSlice([]int{1, 2, 3, 2})
result1 := s.LastIndexOf(0, func(a, b int) bool { return a == b })
result2 := s.LastIndexOf(2, func(a, b int) bool { return a == b })
fmt.Println(result1)
fmt.Println(result2)
// Output:
// -1
// 3
}