Skip to content

Commit

Permalink
doc: move SumBy
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed May 2, 2022
1 parent 109ef0c commit 4fa9fd2
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Supported math helpers:

- Range / RangeFrom / RangeWithSteps
- Clamp
- SumBy

Supported helpers for strings:

Expand Down Expand Up @@ -141,7 +142,6 @@ Supported search helpers:
- Nth
- Sample
- Samples
- SumBy

Other functional programming helpers:

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4fa9fd2

Please sign in to comment.