error-pages/internal/pick/strings_slice.go

21 lines
406 B
Go
Raw Normal View History

2021-10-06 17:38:00 +00:00
package pick
type StringsSlice struct {
s []string
p *picker
2021-10-06 17:38:00 +00:00
}
// NewStringsSlice creates new StringsSlice.
func NewStringsSlice(items []string, mode pickMode) *StringsSlice {
return &StringsSlice{s: items, p: NewPicker(uint32(len(items)-1), mode)}
2021-10-06 17:38:00 +00:00
}
// Pick an element from the strings slice.
func (s *StringsSlice) Pick() string {
if len(s.s) == 0 {
2021-10-06 17:38:00 +00:00
return ""
}
return s.s[s.p.NextIndex()]
2021-10-06 17:38:00 +00:00
}