Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update foreachwhile readme.md #508

Merged
merged 7 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,19 @@ Iterates over collection elements and invokes iteratee for each element collecti
```go
list := []int64{1, 2, -42, 4}

ForEachWhile(list, func(x int64, _ int) bool {
if x < 0 {
return false
}
fmt.Println(x)
return true
lo.ForEachWhile(list, func(x int64, _ int) bool {
if x < 0 {
return false
}
fmt.Println(x)
return true
})

// 1
// 2
```

[[play](https://go.dev/play/p/QnLGt35tnow)]

### Times

Times invokes the iteratee n times, returning an array of the results of each invocation. The iteratee is invoked with index as argument.
Expand Down
3 changes: 2 additions & 1 deletion slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func ForEach[T any](collection []T, iteratee func(item T, index int)) {
}

// ForEachWhile iterates over elements of collection and invokes iteratee for each element
// collection return value decide to continue or break ,just like do while()
// collection return value decide to continue or break, like do while().
// Play: https://go.dev/play/p/QnLGt35tnow
func ForEachWhile[T any](collection []T, iteratee func(item T, index int) (goon bool)) {
for i := range collection {
if !iteratee(collection[i], i) {
Expand Down
Loading