Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate methods added in Go 1.23 #35

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}