mercurial/smartset.py
changeset 33109 247bae545061
parent 33072 6d767d62b25e
child 34070 01c9700fbf9f
equal deleted inserted replaced
33108:208de1534ebd 33109:247bae545061
   764 
   764 
   765     Wrapper structure for generators that provides lazy membership and can
   765     Wrapper structure for generators that provides lazy membership and can
   766     be iterated more than once.
   766     be iterated more than once.
   767     When asked for membership it generates values until either it finds the
   767     When asked for membership it generates values until either it finds the
   768     requested one or has gone through all the elements in the generator
   768     requested one or has gone through all the elements in the generator
       
   769 
       
   770     >>> xs = generatorset([0, 1, 4], iterasc=True)
       
   771     >>> assert xs.last() == xs.last()
       
   772     >>> xs.last()  # cached
       
   773     4
   769     """
   774     """
   770     def __init__(self, gen, iterasc=None):
   775     def __init__(self, gen, iterasc=None):
   771         """
   776         """
   772         gen: a generator producing the values for the generatorset.
   777         gen: a generator producing the values for the generatorset.
   773         """
   778         """
   935             it = self.fastasc
   940             it = self.fastasc
   936         if it is None:
   941         if it is None:
   937             # we need to consume all and try again
   942             # we need to consume all and try again
   938             for x in self._consumegen():
   943             for x in self._consumegen():
   939                 pass
   944                 pass
   940             return self.first()
   945             return self.last()
   941         return next(it(), None)
   946         return next(it(), None)
   942 
   947 
   943     def __repr__(self):
   948     def __repr__(self):
   944         d = {False: '-', True: '+'}[self._ascending]
   949         d = {False: '-', True: '+'}[self._ascending]
   945         return '<%s%s>' % (type(self).__name__, d)
   950         return '<%s%s>' % (type(self).__name__, d)