github.com/tursom/GoCollections@v0.3.10/lang/Slice.go (about)

     1  /*
     2   * Copyright (c) 2022 tursom. All rights reserved.
     3   * Use of this source code is governed by a GPL-3
     4   * license that can be found in the LICENSE file.
     5   */
     6  
     7  package lang
     8  
     9  type Slice[T Object] []T
    10  
    11  func NewSlice[T Object](size, cap int) Slice[T] {
    12  	return make(Slice[T], size, cap)
    13  }
    14  
    15  func (s Slice[T]) Contains(value T) bool {
    16  	for _, e := range s {
    17  		if e.Equals(value) {
    18  			return true
    19  		}
    20  	}
    21  
    22  	return false
    23  }
    24  
    25  func (s *Slice[T]) Append(value T) {
    26  	*s = append(*s, value)
    27  }
    28  
    29  func (s Slice[T]) Size() int {
    30  	return len(s)
    31  }