Skip to content

Commit

Permalink
Simply return an reversed iterator from __reversed__.
Browse files Browse the repository at this point in the history
Currently you're returning an instance of `FunctionalList` with `self.values` set as a `listreverseiterator` object. The problem with this is that user will think that they got an instance of `FunctionalList` back but when they will try to perform any of the operation like `len()`, `__getitem__`, `__setitem__` etc they will end up in errors. So, IMO it's better to return a simple `listreverseiterator` object.
  • Loading branch information
ashwch committed Jul 29, 2014
1 parent a0603f0 commit d32e707
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion magicmethods.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ For our example, let's look at a list that implements some functional constructs
return iter(self.values)

def __reversed__(self):
return FunctionalList(reversed(self.values))
return reversed(self.values)

def append(self, value):
self.values.append(value)
Expand Down

0 comments on commit d32e707

Please sign in to comment.