I add nested tuple (slice) support:
a := []any{"abc", 123, 3.14, 100, []any{"abc", 123, 3.14, 100}}
b := []any{"abc", 123, 3.14, 100, []any{"abc", 123, 3.14, 100}}
c, ok := tuple2.Cmp(a, b)
fmt.Println(c, ok)
```
package tuple2
import (
"cmp"
"reflect"
)
func Cmp(a, b []any) (int, bool) {
if len(a) != len(b) {
return 0, false
}
for i := range a {
if a[i] == nil || b[i] == nil {
return 0, false
}
if _, boolean := a[i].(bool); boolean {
return 0, false
}
if _, boolean := b[i].(bool); boolean {
return 0, false
}
if a, b := reflect.TypeOf(a[i]),
reflect.TypeOf(b[i]); a != b {
return 0, false
}
if a, aOk := a[i].(string); aOk {
if b, bOk := b[i].(string); bOk {
if c := cmp.Compare(a,
b); c != 0 {
return c,
true
}
}
}
if a, aOk := a[i].(int); aOk {
if b, bOk := b[i].(int); bOk {
if c := cmp.Compare(a,
b); c != 0 {
return c,
true
}
}
}
if a, aOk := a[i].(float64); aOk {
if b, bOk := b[i].(float64); bOk {
if c := cmp.Compare(a,
b); c != 0 {
return c,
true
}
}
}
if a, aOk := a[i].([]any); aOk {
if b, bOk := b[i].([]any); bOk {
if c, ok := Cmp(a, b);
ok && c != 0 {
return c,
true
} else if !ok {
return 0,
false
}
}
}
}
return 0, true
}
/*
func main() {
a := []any{"abc", 123, 3.14}
b := []any{"abc", 123, 3.14}
c, ok := tuple2.Cmp(a, b)
fmt.Println(c, ok)
}
*/
```
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/tencent_5DC4B87952382F2A1665A82C9F22B80C2305%40qq.com.