GoCollections/lang/Slice.go

32 lines
527 B
Go
Raw Normal View History

2022-11-27 18:34:18 +08:00
/*
* Copyright (c) 2022 tursom. All rights reserved.
* Use of this source code is governed by a GPL-3
* license that can be found in the LICENSE file.
*/
package lang
type Slice[T Object] []T
func NewSlice[T Object](size, cap int) Slice[T] {
return make(Slice[T], size, cap)
}
func (s Slice[T]) Contains(value T) bool {
for _, e := range s {
if e.Equals(value) {
return true
}
}
return false
}
func (s *Slice[T]) Append(value T) {
*s = append(*s, value)
}
func (s Slice[T]) Size() int {
return len(s)
}