mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
712 B
712 B
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| SampleBy | sampleby | it/find.go#L455 | it | find |
|
https://go.dev/play/p/5WqJN9-zv |
|
|
160 |
Returns a random item from collection, using a custom random index generator.
Example:
seq := func(yield func(int) bool) {
_ = yield(1)
_ = yield(2)
_ = yield(3)
}
// Use custom RNG for predictable results (returns first element)
item := it.SampleBy(seq, func(max int) int { return 0 })
// item == 1