Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
948ac0a1b0
|
22
slice.go
22
slice.go
@@ -1,10 +1,13 @@
|
||||
package extypes
|
||||
|
||||
import "slices"
|
||||
import (
|
||||
"reflect"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type Slice[T comparable] []T
|
||||
type Slice[T any] []T
|
||||
|
||||
func NewSliceFrom[T comparable](slice []T) Slice[T] {
|
||||
func NewSliceFrom[T any](slice []T) Slice[T] {
|
||||
s := make(Slice[T], len(slice))
|
||||
copy(s, slice)
|
||||
return s
|
||||
@@ -22,7 +25,18 @@ func (s Slice[T]) Last() T {
|
||||
return s.Get(s.Len() - 1)
|
||||
}
|
||||
func (s Slice[T]) Index(el T) int {
|
||||
return slices.Index(s, el)
|
||||
for i := range s {
|
||||
//t1 := reflect.TypeOf(el)
|
||||
//t2 := reflect.TypeOf(s[i])
|
||||
//if t1 != t2 {
|
||||
// continue
|
||||
//}
|
||||
if reflect.DeepEqual(s[i], el) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
//return slices.Index(s, el)
|
||||
}
|
||||
|
||||
// Swap is mutable func
|
||||
|
||||
Reference in New Issue
Block a user