Browse files

lazy_chain: when iterating over a slice, the iterator stopped one ind…

…ex too

late.  if using `xfilter()` that could cause needless iteration.
  • Loading branch information...
1 parent e46a489 commit 09f6cb63ba522f9aa647806d40917bc9360109c9 @ambv committed Aug 11, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 src/lck/django/common/
@@ -251,7 +251,13 @@ class lazy_chain(object):
Known issues:
1. If slicing or ``xfilter`` is used, reported ``len()`` is computed by
- iterating over all iterables so performance is weak.
+ iterating over all iterables so performance is weak. Note that
+ ``len()`` is used by ``list()`` when you convert your lazy chain to
+ a list or when iterating over the lazy chain in Django templates.
+ If this is not expected, you can convert to a list using a workaround
+ like this::
+ list(e for e in some_lazy_chain)
2. Indexing on lazy chains uses iteration underneath so performance
is weak. This feature is only available as a last resort. Slicing on the
@@ -347,9 +353,9 @@ def _gen():
if self.step and index % self.step:
+ yield self.xform(element)
if self.stop and index >= self.stop:
- yield self.xform(element)
def __getitem__(self, key):
if isinstance(key, slice):

0 comments on commit 09f6cb6

Please sign in to comment.