From 948ac0a1b0fd1a13e792e1f9364bb2d8bc84c45b Mon Sep 17 00:00:00 2001 From: ScuroNeko Date: Fri, 6 Feb 2026 13:18:11 +0300 Subject: [PATCH] non comparable slices --- slice.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/slice.go b/slice.go index 484cd61..bee26d8 100644 --- a/slice.go +++ b/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