Skip to content

Commit

Permalink
Merge pull request #35 from stefafafan/deprecate-go-123-functions
Browse files Browse the repository at this point in the history
Deprecate methods added in Go 1.23
  • Loading branch information
lufia authored Aug 26, 2024
2 parents 26e7b6c + d450876 commit 33fd982
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
15 changes: 0 additions & 15 deletions godash.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U
return lo.GroupBy(collection, iteratee)
}

// Chunk receives the collection and chunks it into a slice of slices each of the given size.
func Chunk[T any](collection []T, size int) [][]T {
return lo.Chunk(collection, size)
}

// PartitionBy partitions the collection by the iteratee. This is similar to Chunk, but instead of a given size, a function can be applied.
// Use GroupBy if you want a map of slices.
func PartitionBy[T any, K comparable](collection []T, iteratee func(item T) K) [][]T {
Expand All @@ -62,16 +57,6 @@ func KeyBy[K comparable, V any](collection []V, iteratee func(item V) K) map[K]V
return lo.KeyBy(collection, iteratee)
}

// Keys returns the keys of the map as a slice.
func Keys[K comparable, V any](in map[K]V) []K {
return lo.Keys(in)
}

// Values returns the values of the map as a slice.
func Values[K comparable, V any](in map[K]V) []V {
return lo.Values(in)
}

// Sum returns a sum of the values within the slice. The values of the slice need to be numbers.
func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T {
return lo.Sum(collection)
Expand Down
22 changes: 22 additions & 0 deletions godash_compat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !go1.23

package godash

import (
"github.com/samber/lo"
)

// Chunk receives the collection and chunks it into a slice of slices each of the given size.
func Chunk[T any](collection []T, size int) [][]T {
return lo.Chunk(collection, size)
}

// Keys returns the keys of the map as a slice.
func Keys[K comparable, V any](in map[K]V) []K {
return lo.Keys(in)
}

// Values returns the values of the map as a slice.
func Values[K comparable, V any](in map[K]V) []V {
return lo.Values(in)
}
28 changes: 28 additions & 0 deletions godash_go123.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build go1.23

package godash

import (
"github.com/samber/lo"
)

// Chunk receives the collection and chunks it into a slice of slices each of the given size.
//
// Deprecated: Use https://pkg.go.dev/slices#Chunk instead.
func Chunk[T any](collection []T, size int) [][]T {
return lo.Chunk(collection, size)
}

// Keys returns the keys of the map as a slice.
//
// Deprecated: Use https://pkg.go.dev/maps#Keys instead.
func Keys[K comparable, V any](in map[K]V) []K {
return lo.Keys(in)
}

// Values returns the values of the map as a slice.
//
// Deprecated: Use https://pkg.go.dev/maps#Values instead.
func Values[K comparable, V any](in map[K]V) []V {
return lo.Values(in)
}

0 comments on commit 33fd982

Please sign in to comment.