[Python-ideas] unify usage of mutable and immutable objects
语言破碎处
mlet_it_bew at 126.com
Tue Feb 28 21:20:23 EST 2017
> We are not going to change the implementation of sets so fundamentally,
> mostly because having O(1) behaviors is so nice (add, remove, membership
> check, etc).
What I want are such interfaces (no matter with standard set):
class IDynSet:
# "Dyn" means it have methods like ipop_both
def ipop_both(self):
if hasattr(self, 'pop_mutable'):
elem = self.pop_mutable()
elif hasattr(self, 'ipop_immutable'):
elem, self = self.ipop_immutable()
else: raise
return elem, self
class IMutableDynSet(IDynSet):
def pop_mutable(self):
return self.pop()
class IImutableDynSet(IDynSet):
def ipop_immutable(self):
elem, new = self.ipop() # ipop not pop
return elem, new
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/9e72cc81/attachment-0001.html>
More information about the Python-ideas
mailing list