diff --git a/boltons/iterutils.py b/boltons/iterutils.py index 23b38a5..036eb5a 100644 --- a/boltons/iterutils.py +++ b/boltons/iterutils.py @@ -165,7 +165,6 @@ def chunked(src, size, count=None, **kw): else: return list(itertools.islice(chunk_iter, count)) - def chunked_iter(src, size, **kw): """Generates *size*-sized chunks from *src* iterable. Unless the optional *fill* keyword argument is provided, iterables not even @@ -213,6 +212,15 @@ def chunked_iter(src, size, **kw): yield postprocess(cur_chunk) return +def pairwise(src, count=None, **kw): + """Shortcut for calling chunked with size set to 2 + """ + return chunked(src, 2, count, **kw) + +def pairwise_iter(src, **kw): + """Shortcut for calling chunked_iter with size set to 2 + """ + return chunked_iter(src, 2, **kw) def windowed(src, size): """Returns tuples with exactly length *size*. If the iterable is diff --git a/docs/iterutils.rst b/docs/iterutils.rst index ef90a4a..bdd206f 100644 --- a/docs/iterutils.rst +++ b/docs/iterutils.rst @@ -14,6 +14,8 @@ from the standard library. .. autofunction:: split_iter .. autofunction:: chunked .. autofunction:: chunked_iter +.. autofunction:: pairwise +.. autofunction:: pairwise_iter .. autofunction:: windowed .. autofunction:: windowed_iter