From 4fa9fd28a92793f4ea7a156ba172a5933f4a22ae Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Mon, 2 May 2022 14:51:58 +0200 Subject: [PATCH] doc: move SumBy --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) 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.