From aa56af2c4b6868b4c1852c5ad3a7d5784fdf21fc Mon Sep 17 00:00:00 2001 From: sia Date: Tue, 6 Aug 2024 14:29:25 +0800 Subject: [PATCH 1/7] update readme.md for lo.ForEachWhile play and example code --- README.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c5b44297..e5c481bb 100644 --- a/README.md +++ b/README.md @@ -432,20 +432,25 @@ lop.ForEach([]string{"hello", "world"}, func(x string, _ int) { Iterates over collection elements and invokes iteratee for each element collection return value decide to continue or break, like do while(). ```go + +import "github.com/samber/lo" + 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. From 1e35a2d3415075378bd857b2bbd4f64210d05c57 Mon Sep 17 00:00:00 2001 From: sia Date: Tue, 6 Aug 2024 14:31:00 +0800 Subject: [PATCH 2/7] delete unnecessary new line --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e5c481bb..d7106915 100644 --- a/README.md +++ b/README.md @@ -445,8 +445,6 @@ lo.ForEachWhile(list, func(x int64, _ int) bool { return true }) - - // 1 // 2 ``` From ed12d30e6c9bf458fe63e0c097764b60b7e1c798 Mon Sep 17 00:00:00 2001 From: sia Date: Tue, 6 Aug 2024 14:33:24 +0800 Subject: [PATCH 3/7] delete unnecessary new line again --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index d7106915..b9af751d 100644 --- a/README.md +++ b/README.md @@ -444,7 +444,6 @@ lo.ForEachWhile(list, func(x int64, _ int) bool { fmt.Println(x) return true }) - // 1 // 2 ``` From a042560fd7961981f1e4adff4b78bae4e55676f0 Mon Sep 17 00:00:00 2001 From: sia Date: Tue, 6 Aug 2024 17:03:10 +0800 Subject: [PATCH 4/7] update play link for foreachWhile() --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9af751d..58d6dba1 100644 --- a/README.md +++ b/README.md @@ -447,7 +447,7 @@ lo.ForEachWhile(list, func(x int64, _ int) bool { // 1 // 2 ``` -[[play]](https://go.dev/play/p/QnLGt35tnow) +[[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. From f96bdc37dad5e3ae2f72abb102a18999c5f7b56e Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Sat, 10 Aug 2024 01:19:30 +0200 Subject: [PATCH 5/7] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 58d6dba1..53dbcea5 100644 --- a/README.md +++ b/README.md @@ -432,7 +432,6 @@ lop.ForEach([]string{"hello", "world"}, func(x string, _ int) { Iterates over collection elements and invokes iteratee for each element collection return value decide to continue or break, like do while(). ```go - import "github.com/samber/lo" list := []int64{1, 2, -42, 4} @@ -447,7 +446,9 @@ lo.ForEachWhile(list, func(x int64, _ int) bool { // 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. From 6a44ef6eb41ea0e5fe01671b747f3cf143388c00 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Sat, 10 Aug 2024 01:20:12 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 53dbcea5..3f73cc8e 100644 --- a/README.md +++ b/README.md @@ -432,8 +432,6 @@ lop.ForEach([]string{"hello", "world"}, func(x string, _ int) { Iterates over collection elements and invokes iteratee for each element collection return value decide to continue or break, like do while(). ```go -import "github.com/samber/lo" - list := []int64{1, 2, -42, 4} lo.ForEachWhile(list, func(x int64, _ int) bool { From b838b865bb493cb1dafc87f887fd4a68b48d21f1 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Sat, 10 Aug 2024 01:22:03 +0200 Subject: [PATCH 7/7] Update slice.go --- slice.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slice.go b/slice.go index 431aaf04..d2d3fd84 100644 --- a/slice.go +++ b/slice.go @@ -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) {