diff --git a/README.md b/README.md index 08cd04d1..10107ce0 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ Supported math helpers: - Range / RangeFrom / RangeWithSteps - Clamp +- SumBy Supported helpers for strings: @@ -141,7 +142,6 @@ Supported search helpers: - Nth - Sample - Samples -- SumBy Other functional programming helpers: @@ -840,6 +840,19 @@ r3 := lo.Clamp(42, -10, 10) // 10 ``` +### SumBy + +Summarizes the values in a collection using the given return value from the iteration function. +If collection is empty 0 is returned. + +```go +strings := []string{"foo", "bar"} +sum := lo.SumBy(strings, func(item string) int { + return len(item) +}) +// 6 +``` + ### Substring Return part of a string. @@ -1191,19 +1204,6 @@ lo.Samples[string]([]string{"a", "b", "c"}, 3) // []string{"a", "b", "c"} in random order ``` -### SumBy - -Summarizes the values in a collection using the given return value from the iteration function. -If collection is empty 0 is returned. - -```go -strings := []string{"foo", "bar"} -sum := lo.SumBy(strings, func(item string) int { - return len(item) -}) -// 6 -``` - ### Ternary A 1 line if/else statement.