mirror of
https://github.com/maaslalani/confetty.git
synced 2024-11-14 11:46:43 +00:00
feat: generic array sampling
This commit is contained in:
parent
5e9098632d
commit
c3f294bd48
@ -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
15
go.mod
@ -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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user