jaswdr / faker

:rocket: Ultimate fake data generator for Go with zero dependencies
https://pkg.go.dev/github.com/jaswdr/faker
MIT License
566 stars 59 forks source link

feat: Add RandomMapKey and RandomMapValue #182

Closed mathieu-lemay closed 1 week ago

mathieu-lemay commented 1 week ago

Description

Add two generic functions, analog to to RandomStringMapKey and RandomStringMapValue, in the same way RandomElement is to RandomStringElement.

This was something I felt was missing as I was trying to get a random map element from a map than was not a map[string]string.

Unlike their String counterpart though, no sorting is performed. Doing a sort would require the generics to be constrained to cmd.Ordered which I feel is too restrictive.

Are you trying to fix an existing issue?

No

Go Version

$ go version
go version go1.23.2 darwin/arm64

Go Tests

$ go test
PASS
ok      github.com/jaswdr/faker/v2      7.547s
jaswdr commented 1 week ago

@mathieu-lemay thank you for the PR 👍 look good to me, I'll just reorganize the code and release it under the next minor version