feat: add SampleBy and SamplesBy#516
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.
Why this method doesn't call SamplesBy with count=1 and return the first entry?
There was a problem hiding this comment.
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.
But if you want me to update it... by all means and I change it!
|
@ccoVeille I don't have the rights to merge this. Not sure if @samber first needs to approve it? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #516 +/- ##
==========================================
- Coverage 94.33% 94.15% -0.18%
==========================================
Files 17 18 +1
Lines 2790 3065 +275
==========================================
+ Hits 2632 2886 +254
- Misses 154 168 +14
- Partials 4 11 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Why?
See #512
What?
Added a
SampleByandSamplesBythat accepts anintFuncthat is the generator of the indexes. This way, a client of thelolibrary would be able to provide their own seeded random generator.Example?