Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Mar 8, 2022
1 parent 6b305f0 commit 452bc08
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Supported helpers for slices:

- Filter
- Map
- FlatMap
- Reduce
- ForEach
- Times
Expand All @@ -72,6 +73,7 @@ Supported helpers for maps:
- Entries
- FromEntries
- Assign (merge of maps)
- MapValues

Supported helpers for tuples:

Expand All @@ -81,6 +83,7 @@ Supported helpers for tuples:
Supported intersection helpers:

- Contains
- ContainsBy
- Every
- Some
- Intersect
Expand Down Expand Up @@ -135,6 +138,20 @@ lop.Map[int64, string]([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
// []string{"1", "2", "3", "4"}
```

### FlatMap

Manipulates a slice and transforms and flattens it to a slice of another type.

```go
lo.FlatMap[int, string]([]int{0, 1, 2}, func(x int, _ int) []string {
return []string{
strconv.FormatInt(x, 10),
strconv.FormatInt(x, 10),
}
})
// []string{"0", "0", "1", "1", "2", "2"}
```

### Filter

Iterates over elements of collection, returning an array of all elements predicate returns truthy for.
Expand All @@ -155,6 +172,17 @@ present := lo.Contains[int]([]int{0, 1, 2, 3, 4, 5}, 5)
// true
```

### Contains

Returns true if predicate function return true.

```go
present := lo.ContainsBy[int]([]int{0, 1, 2, 3, 4, 5}, func(x int) bool {
return x == 3
})
// true
```

### Reduce

Reduces collection to a value which is the accumulated result of running each element in collection through accumulator, where each successive invocation is supplied the return value of the previous.
Expand Down Expand Up @@ -448,6 +476,19 @@ mergedMaps := lo.Assign[string, int](
// map[string]int{"a": 1, "b": 3, "c": 4}
```

### MapValues

Manipulates a map values and transforms it to a map of another type.

```go
m1 := map[int]int64{1: 1, 2: 2, 3: 3}

m2 := lo.MapValues[int, int64, string](m, func(x int64, _ int) string {
return strconv.FormatInt(x, 10)
})
// map[int]string{1: "1", 2: "2", 3: "3"}
```

### Zip2 -> Zip9

Zip creates a slice of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
Expand Down

0 comments on commit 452bc08

Please sign in to comment.