mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
refactor: remove some redundant checks (#771)
This commit is contained in:
@@ -88,14 +88,6 @@ func SumBy[T any, R constraints.Float | constraints.Integer | constraints.Comple
|
||||
// Product gets the product of the values in a collection. If collection is empty 1 is returned.
|
||||
// Play: https://go.dev/play/p/2_kjM_smtAH
|
||||
func Product[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T {
|
||||
if collection == nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
if len(collection) == 0 {
|
||||
return 1
|
||||
}
|
||||
|
||||
var product T = 1
|
||||
for i := range collection {
|
||||
product *= collection[i]
|
||||
@@ -106,14 +98,6 @@ func Product[T constraints.Float | constraints.Integer | constraints.Complex](co
|
||||
// ProductBy summarizes the values in a collection using the given return value from the iteration function. If collection is empty 1 is returned.
|
||||
// Play: https://go.dev/play/p/wadzrWr9Aer
|
||||
func ProductBy[T any, R constraints.Float | constraints.Integer | constraints.Complex](collection []T, iteratee func(item T) R) R {
|
||||
if collection == nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
if len(collection) == 0 {
|
||||
return 1
|
||||
}
|
||||
|
||||
var product R = 1
|
||||
for i := range collection {
|
||||
product *= iteratee(collection[i])
|
||||
|
||||
Reference in New Issue
Block a user