mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
refactor: fix bad code smell
This commit is contained in:
@@ -170,33 +170,29 @@ func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) boo
|
|||||||
|
|
||||||
// Every return true if all of the values in the slice pass the predicate function.
|
// Every return true if all of the values in the slice pass the predicate function.
|
||||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool {
|
func Every[T any](slice []T, predicate func(index int, item T) bool) bool {
|
||||||
var currentLength int
|
|
||||||
|
|
||||||
for i, v := range slice {
|
for i, v := range slice {
|
||||||
if predicate(i, v) {
|
if !predicate(i, v) {
|
||||||
currentLength++
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentLength == len(slice)
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// None return true if all the values in the slice mismatch the criteria
|
// None return true if all the values in the slice mismatch the criteria
|
||||||
func None[T any](slice []T, predicate func(index int, item T) bool) bool {
|
func None[T any](slice []T, predicate func(index int, item T) bool) bool {
|
||||||
|
l := 0
|
||||||
var currentLength int
|
|
||||||
for i, v := range slice {
|
for i, v := range slice {
|
||||||
if !predicate(i, v) {
|
if !predicate(i, v) {
|
||||||
currentLength++
|
l++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentLength == len(slice)
|
return l == len(slice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some return true if any of the values in the list pass the predicate function.
|
// Some return true if any of the values in the list pass the predicate function.
|
||||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool {
|
func Some[T any](slice []T, predicate func(index int, item T) bool) bool {
|
||||||
|
|
||||||
for i, v := range slice {
|
for i, v := range slice {
|
||||||
if predicate(i, v) {
|
if predicate(i, v) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user