refactor: remove some redundant checks (#771)

This commit is contained in:
d-enk
2026-01-12 22:42:12 +03:00
committed by GitHub
parent 7d777446ab
commit 123d5c2531
4 changed files with 10 additions and 26 deletions
-16
View File
@@ -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])