-
-
Notifications
You must be signed in to change notification settings - Fork 823
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
feat: add SampleBy and SamplesBy #516
base: master
Are you sure you want to change the base?
Conversation
find.go
Outdated
} | ||
|
||
// SampleBy returns a random item from collection, using intFunc as the random index generator. | ||
func SampleBy[T any](collection []T, intFunc func(int) int) T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this method doesn't call SamplesBy with count=1 and return the first entry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the original implementation of the Sample
doesn't use Samples
. I didn't want to change any implementation of existing functions. Also... not sure if there's that much of a benefit in doing so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you want me to update it... by all means and I change it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for owner's feedback
cc @samber
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I posted this, but feel free to merge.
@ccoVeille I don't have the rights to merge this. Not sure if @samber first needs to approve it? |
Why?
See #512
What?
Added a
SampleBy
andSamplesBy
that accepts anintFunc
that is the generator of the indexes. This way, a client of thelo
library would be able to provide their own seeded random generator.Example?