Skip to content

Commit

Permalink
Revert "Add new method Concat (#376)"
Browse files Browse the repository at this point in the history
This reverts commit 940ded8.
  • Loading branch information
samber authored Jun 29, 2024
1 parent 940ded8 commit e14868c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 43 deletions.
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ Supported helpers for slices:
- [CountValuesBy](#countvaluesby)
- [Subset](#subset)
- [Slice](#slice)
- [Concat](#concat)
- [Replace](#replace)
- [ReplaceAll](#replaceall)
- [Compact](#compact)
Expand Down Expand Up @@ -907,21 +906,6 @@ slice := lo.Slice(in, 4, 3)

[[play](https://go.dev/play/p/8XWYhfMMA1h)]

### Concat

Returns a new slice containing all the elements in collections. Concat conserves the order of the elements.

```go
slice := lo.Concat([]int{1, 2}, []int{3, 4})
// []int{1, 2, 3, 4}

slice := lo.Concat(nil, []int{1, 2}, nil, []int{3, 4}, nil)
// []int{1, 2, 3, 4}

slice := lo.Concat[int]()
// []int{}
```

### Replace

Returns a copy of the slice with the first n non-overlapping instances of old replaced by new.
Expand Down
17 changes: 0 additions & 17 deletions slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,23 +562,6 @@ func Slice[T any](collection []T, start int, end int) []T {
return collection[start:end]
}

// Concat returns a new slice containing all the elements in
// collections. Concat conserves the order of the elements.
func Concat[T any](collections ...[]T) []T {
size := 0
for i := range collections {
size += len(collections[i])
}

result := make([]T, 0, size) // preallocate memory for the output slice
for i := 0; i < len(collections); i++ {
// `result` memory address is not expected to change, because we preallocated enough memory
result = append(result, collections[i]...)
}

return result
}

// Replace returns a copy of the slice with the first n non-overlapping instances of old replaced by new.
// Play: https://go.dev/play/p/XfPzmf9gql6
func Replace[T comparable](collection []T, old T, new T, n int) []T {
Expand Down
10 changes: 0 additions & 10 deletions slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,6 @@ func TestSlice(t *testing.T) {
is.Equal([]int{0, 1, 2, 3, 4}, out18)
}

func TestConcat(t *testing.T) {
t.Parallel()
is := assert.New(t)

is.Equal([]int{1, 2, 3, 4}, Concat([]int{1, 2}, []int{3, 4}))
is.Equal([]int{1, 2, 3, 4}, Concat(nil, []int{1, 2}, nil, []int{3, 4}, nil))
is.Equal([]int{}, Concat[int](nil, nil))
is.Equal([]int{}, Concat[int]())
}

func TestReplace(t *testing.T) {
t.Parallel()
is := assert.New(t)
Expand Down

0 comments on commit e14868c

Please sign in to comment.