Skip to content

Commit a39de11

Browse files
committed
tuple: implement __eq__ and __ne__
1 parent ff5d114 commit a39de11

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

py/tuple.go

+32
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,35 @@ var _ I__iter__ = Tuple(nil)
106106
var _ I__getitem__ = Tuple(nil)
107107

108108
// var _ richComparison = Tuple(nil)
109+
110+
func (a Tuple) M__eq__(other Object) Object {
111+
b, ok := other.(Tuple)
112+
if !ok {
113+
return NotImplemented
114+
}
115+
if len(a) != len(b) {
116+
return False
117+
}
118+
for i := range a {
119+
if Eq(a[i], b[i]) == False {
120+
return False
121+
}
122+
}
123+
return True
124+
}
125+
126+
func (a Tuple) M__ne__(other Object) Object {
127+
b, ok := other.(Tuple)
128+
if !ok {
129+
return NotImplemented
130+
}
131+
if len(a) != len(b) {
132+
return True
133+
}
134+
for i := range a {
135+
if Eq(a[i], b[i]) == False {
136+
return True
137+
}
138+
}
139+
return False
140+
}

0 commit comments

Comments
 (0)