Mercurial > hg
changeset 22808:228b0aafb1ce
smartset: add first and last methods
In multiple places in the code, we use `someset[0]` or `someset[-1]`. This
works only because the `someset` is usually a baseset. For the same reason we
introduce a `first` and `last` methods to be implemented for all smartset
classes.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 06 Oct 2014 11:46:53 -0700 |
parents | cd43195ef876 |
children | 88dad916c008 |
files | mercurial/revset.py |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revset.py Tue Oct 07 00:20:00 2014 -0700 +++ b/mercurial/revset.py Mon Oct 06 11:46:53 2014 -0700 @@ -2262,6 +2262,18 @@ raise ValueError('arg is an empty sequence') return max(self) + def first(self): + """return the first element in the set (user iteration perspective) + + Return None if the set is empty""" + raise NotImplementedError() + + def last(self): + """return the last element in the set (user iteration perspective) + + Return None if the set is empty""" + raise NotImplementedError() + def reverse(self): """reverse the expected iteration order""" raise NotImplementedError()