1.1 --- a/lib/__builtins__/tuple.py Thu Jul 12 18:19:02 2018 +0200
1.2 +++ b/lib/__builtins__/tuple.py Sun Jul 22 00:19:35 2018 +0200
1.3 @@ -22,7 +22,8 @@
1.4 from __builtins__.iteration.iterator import itemiterator
1.5 from __builtins__.sequence import hashable, unpackable
1.6 from native import tuple_init, \
1.7 - list_element, list_len, list_setsize, list_setelement
1.8 + list_element, list_len, list_setsize, list_setelement, \
1.9 + isinstance as _isinstance
1.10
1.11 class tuple(unpackable, hashable):
1.12
1.13 @@ -73,7 +74,13 @@
1.14
1.15 return list_len(self.__data__)
1.16
1.17 - def __add__(self, other): pass
1.18 + def __add__(self, other):
1.19 +
1.20 + "Add this tuple to 'other'."
1.21 +
1.22 + if not _isinstance(other, tuple):
1.23 + raise TypeError
1.24 + return tuple(tuplepair(self, other))
1.25
1.26 def __str__(self):
1.27
1.28 @@ -110,4 +117,28 @@
1.29
1.30 raise TypeError
1.31
1.32 +class tuplepair:
1.33 +
1.34 + "A combination of tuples."
1.35 +
1.36 + def __init__(self, a, b):
1.37 + self.a = a
1.38 + self.b = b
1.39 +
1.40 + def __len__(self):
1.41 +
1.42 + "Return the combined length of the tuples."
1.43 +
1.44 + return len(self.a) + len(self.b)
1.45 +
1.46 + def __getitem__(self, index):
1.47 +
1.48 + "Return the value from 'index' in the combined tuple."
1.49 +
1.50 + asize = len(self.a)
1.51 + if index < asize:
1.52 + return self.a.__get_single_item__(index)
1.53 + else:
1.54 + return self.b.__get_single_item__(index - asize)
1.55 +
1.56 # vim: tabstop=4 expandtab shiftwidth=4