feat: generic array sampling

This commit is contained in:
Maas Lalani 2022-04-16 14:20:15 -04:00
parent 5e9098632d
commit c3f294bd48
No known key found for this signature in database
GPG Key ID: 5A6ED5CBF1A0A000
2 changed files with 17 additions and 5 deletions

View File

@ -2,8 +2,7 @@ package array
import "math/rand"
// Sample returns a random element from an array
// (can't wait for generics!)
func Sample(s []string) string {
return s[rand.Intn(len(s))]
// Sample returns a random element from a generic array
func Sample[T any](arr []T) T {
return arr[rand.Intn(len(arr))]
}

15
go.mod
View File

@ -1,9 +1,22 @@
module github.com/maaslalani/confetty
go 1.16
go 1.18
require (
github.com/charmbracelet/bubbletea v0.20.0
github.com/charmbracelet/harmonica v0.2.0
github.com/charmbracelet/lipgloss v0.5.0
)
require (
github.com/containerd/console v1.0.3 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // indirect
)