Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
unicode_literals)

import six
from itertools import product
from itertools import product, cycle
from six.moves import zip, reduce
from operator import mul, add
import copy
Expand Down Expand Up @@ -62,6 +62,9 @@ class Cycler(object):
Function which composes the 'left' and 'right' cyclers.

"""
def __call__(self):
return cycle(self)

def __init__(self, left, right=None, op=None):
"""Semi-private init

Expand Down
10 changes: 10 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ which returns a new `Cycler` with a new label, but the same values.
cycler('ec', color_cycle)


Iterating over a `Cycler` results in the finite list of entries, to
get an infinite cycle, call the `Cycler` object (a-la a generator)

.. ipython:: python

cc = color_cycle()
for j, c in zip(range(5), cc):
print(j, c)


Composition
-----------

Expand Down
16 changes: 14 additions & 2 deletions test_cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import six
from six.moves import zip, range
from cycler import cycler, Cycler
from nose.tools import assert_equal, assert_raises
from itertools import product
from nose.tools import assert_equal, assert_raises, assert_true
from itertools import product, cycle
from operator import add, iadd, mul, imul


Expand Down Expand Up @@ -148,3 +148,15 @@ def test_repr():

yield _repr_tester_helper, '_repr_html_', c + c2, sum_html
yield _repr_tester_helper, '_repr_html_', c * c2, prod_html


def test_call():
c = cycler('c', 'rgb')
c_cycle = c()
assert_true(isinstance(c_cycle, cycle))
j = 0
for a, b in zip(2*c, c_cycle):
j += 1
assert_equal(a, b)

assert_equal(j, len(c) * 2)