source: utilitiespy/tudelft/utilities/immutablelist/Tuple.py@ 1285

Last change on this file since 1285 was 314, checked in by wouter, 3 years ago

#105 added JoinedList, MapList, Tuple, release 1.0.5

File size: 795 bytes
Line 
1from typing import TypeVar, Generic
2
3T1 = TypeVar('T1')
4T2 = TypeVar('T2')
5
6
7class Tuple(Generic[T1,T2]):
8 '''
9 tuple with two elements of different types. Immutable
10 @param <T1> type of the first element of the tuple
11 @param <T2> type of the second element of the tuple
12 '''
13
14 def __init__(self, element1:T1 , element2:T2 ):
15 self._element1 = element1
16 self._element2 = element2
17
18 def get1(self) -> T1:
19 return self._element1
20
21 def get2(self)->T2 :
22 return self._element2
23
24 def __repr__(self)->str:
25 return "<" + str(self._element1) + "," + str(self._element2) + ">"
26
27 def __hash__(self):
28 return hash((self._element1, self._element2))
29
30 def __eq__(self, other):
31 return isinstance(other, self.__class__) \
32 and self._element1==other._element1\
33 and self._element2==other._element2
Note: See TracBrowser for help on using the repository browser.