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

Add shuffle slice utility #123

Open
lil5 opened this issue Aug 20, 2022 · 1 comment
Open

Add shuffle slice utility #123

lil5 opened this issue Aug 20, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request go1.18-migration
Milestone

Comments

@lil5
Copy link

lil5 commented Aug 20, 2022

Is your feature request related to a problem? Please describe.
I'm trying to fake a randomized array of unique enums

Describe the solution you'd like
To include shuffleSlice as Faker.ShuffleSlice

func ShuffleSlice[T any](slice []T) []T {
	rand.Shuffle(len(slice), func(i, j int) {
		slice[i], slice[j] = slice[j], slice[i]
	})

	return slice
}

go playground example
https://play.golang.com/p/1rQ2O-0aNOx

@lil5 lil5 added the enhancement New feature or request label Aug 20, 2022
@jaswdr jaswdr self-assigned this Dec 25, 2022
@jaswdr jaswdr added this to the go1.18 milestone Dec 25, 2022
@jaswdr
Copy link
Owner

jaswdr commented Dec 25, 2022

Hello @lil5, unfortunately it is not possible to use Generics because we still support versions <= 1.18. I'll add this issue to our go1.18 migration plan. I'll include this idea when we bump our Go version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go1.18-migration
Projects
None yet
Development

No branches or pull requests

2 participants