mirror of
https://github.com/tursom/GoCollections.git
synced 2025-03-16 02:50:31 +08:00
32 lines
527 B
Go
32 lines
527 B
Go
|
/*
|
||
|
* 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)
|
||
|
}
|