Skip to content

Commit

Permalink
docs: add the duplicates into the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Mar 2, 2022
1 parent a883d5c commit 463845b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ The corresponding chained function is `collect.UseSlice()`

</details>

- `Unique` removes duplicate elements from slices
- `Unique` removes duplicate elements in the slice

<details>
<summary>Examples</summary>
Expand All @@ -208,6 +208,18 @@ The corresponding chained function is `collect.UseSlice()`

</details>

- `Duplicates` gets the duplicate elements in the slice

<details>
<summary>Examples</summary>

```go
d := []string{"a", "b", "a", "c"}
collect.Duplicates(d) // map[int]string{2: "a"}
```

</details>

- `Merge` merges the current slice with other slices

<details>
Expand Down Expand Up @@ -830,7 +842,7 @@ Due to Golang's support for generics, it is [not possible to define generic type

</details>

- `Times` creates a new collection of slices by calling the callback with specified number of times
- `Times` creates a new collection of slice by calling the callback with specified number of times

<details>
<summary>Examples</summary>
Expand Down
12 changes: 12 additions & 0 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ import collect "github.com/sxyazi/go-collection"

</details>

- Duplicates:获取切片中的重复元素

<details>
<summary>例子</summary>

```go
d := []string{"a", "b", "a", "c"}
collect.Duplicates() // map[int]string{2: "a"}
```

</details>

- Merge:将当前切片与其它切片合并

<details>
Expand Down
2 changes: 1 addition & 1 deletion converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func OffsetToIndex(actual, offset int, args ...int) (int, int) {
return offset, offset + length
}

func NumberFrom[N constraints.Integer | constraints.Float, T ~[]E, E comparable](c *SliceCollection[T, E]) *NumberCollection[[]N, N] {
func NumberFrom[N constraints.Integer | constraints.Float, T ~[]E, E any](c *SliceCollection[T, E]) *NumberCollection[[]N, N] {
if c.Empty() {
return &NumberCollection[[]N, N]{}
}
Expand Down
2 changes: 1 addition & 1 deletion functional.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func Count[T ~[]E, E comparable](items T) map[E]int {
return times
}

func Times[T ~[]E, E any](number int, callback func(number int) E) *SliceCollection[T, E] {
func Times[T []E, E any](number int, callback func(number int) E) *SliceCollection[T, E] {
items := make(T, number)
for i := 0; i < number; i++ {
items[i] = callback(i + 1)
Expand Down
3 changes: 3 additions & 0 deletions tests/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ func TestSlice_Duplicates(t *testing.T) {
if !UseSlice([]int{1, 2, 2, 3}).Duplicates().Same(map[int]int{2: 2}) {
t.Fail()
}
if !UseSlice([]string{"a", "b", "a", "c"}).Duplicates().Same(map[int]string{2: "a"}) {
t.Fail()
}

s1, s2 := []int{1, 2, 3}, []int{4, 5, 6}
if !UseSlice([][]int{s1, s2, s1}).Duplicates().Same(map[int][]int{2: s1}) {
Expand Down
2 changes: 1 addition & 1 deletion tests/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tests

type Foo struct {
Bar any
Bar string
}

type User struct {
Expand Down

0 comments on commit 463845b

Please sign in to comment.