mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.1 KiB
1.1 KiB
name, slug, sourceRef, category, subCategory, variantHelpers, similarHelpers, position, signatures
| name | slug | sourceRef | category | subCategory | variantHelpers | similarHelpers | position | signatures | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ProductByErr | productbyerr | math.go#L134 | core | math |
|
|
71 |
|
Calculates the product of values computed by a predicate. Returns 1 for nil or empty collections.
If the iteratee returns an error, iteration stops and the error is returned.
strings := []string{"foo", "bar"}
result, err := lo.ProductByErr(strings, func(item string) (int, error) {
return len(item), nil
})
// 9, <nil>
Example with error:
strings := []string{"foo", "bar", "baz"}
result, err := lo.ProductByErr(strings, func(item string) (int, error) {
if item == "bar" {
return 0, fmt.Errorf("bar is not allowed")
}
return len(item), nil
})
// 3, error("bar is not allowed")