@@ -62,13 +62,54 @@ func isComparable(v any) bool {
6262 }
6363}
6464
65+ // isContainsElement checks whether the array or slice contains the specific element or not. It'll
66+ // panic if the source is not an array or a slice, and it'll also panic if the element's type is
67+ // not the same as the source's element.
68+ func isContainsElement (source , elem any ) bool {
69+ st := reflect .ValueOf (source )
70+ if st .Kind () == reflect .Ptr {
71+ st = st .Elem ()
72+ }
73+ if st .Kind () != reflect .Array && st .Kind () != reflect .Slice {
74+ panic ("require array or slice" )
75+ }
76+ if ok , isMixed := isSameType (st .Type ().Elem (), reflect .TypeOf (elem )); ! ok && ! isMixed {
77+ panic ("require same type" )
78+ }
79+
80+ if st .Len () == 0 {
81+ return false
82+ }
83+
84+ ev := reflect .ValueOf (elem )
85+
86+ for i := 0 ; i < st .Len (); i ++ {
87+ ok := isEqual (st .Index (i ), ev )
88+ if ok {
89+ return true
90+ }
91+ }
92+ return false
93+ }
94+
6595// isEqual checks the equality of the values.
6696func isEqual (x , y any ) bool {
6797 if x == nil || y == nil {
6898 return x == y
6999 }
70- v1 := reflect .ValueOf (x )
71- v2 := reflect .ValueOf (y )
100+
101+ var v1 , v2 reflect.Value
102+ if xv , ok := x .(reflect.Value ); ok {
103+ v1 = xv
104+ } else {
105+ v1 = reflect .ValueOf (x )
106+ }
107+ if yv , ok := y .(reflect.Value ); ok {
108+ v2 = yv
109+ } else {
110+ v2 = reflect .ValueOf (y )
111+ }
112+
72113 if isSame , isMixSign := isSameType (v1 .Type (), v2 .Type ()); ! isSame {
73114 if isMixSign {
74115 return isEqualForMixSignInt (v1 , v2 )
@@ -86,6 +127,8 @@ func isEqual(x, y any) bool {
86127 return v1 .Float () == v2 .Float ()
87128 case reflect .Complex64 , reflect .Complex128 :
88129 return v1 .Complex () == v2 .Complex ()
130+ case reflect .String :
131+ return v1 .String () == v2 .String ()
89132 case reflect .Slice :
90133 return isSliceEqual (v1 , v2 )
91134 default :
0 commit comments