Add comments to generic functions

This commit is contained in:
Jason Streifling 2024-10-20 12:30:23 +02:00
parent c0f5306715
commit b6b8970810

View File

@ -16,6 +16,7 @@ type Countable interface {
*xml.Attr | *Person | *Category | *Link | *ExtensionElement | *Entry *xml.Attr | *Person | *Category | *Link | *ExtensionElement | *Entry
} }
// addToSlice adds a Countable to to a *[]Countable
func addToSlice[C Countable](slice *[]C, countable C) { func addToSlice[C Countable](slice *[]C, countable C) {
if *slice == nil { if *slice == nil {
*slice = make([]C, 0) *slice = make([]C, 0)
@ -23,6 +24,8 @@ func addToSlice[C Countable](slice *[]C, countable C) {
*slice = append(*slice, countable) *slice = append(*slice, countable)
} }
// deleteFromSlice deletes the Countable with the index from the *[]Countable.
// It return an error.
func deleteFromSlice[C Countable](slice *[]C, id int) error { func deleteFromSlice[C Countable](slice *[]C, id int) error {
length := len(*slice) length := len(*slice)
if id > length { if id > length {