non comparable slices

This commit is contained in:
2026-02-06 13:18:11 +03:00
parent 7d930b6e97
commit 948ac0a1b0

View File

@@ -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