LibCST/libcst/_parser/_custom_itertools.py
Jennifer Taylor 3fb60b9706 Make parser package private
Now that this is imported from the top level, make it private.
2019-07-26 12:48:22 -07:00

19 lines
635 B
Python

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# pyre-strict
from itertools import zip_longest
from typing import Iterable, Iterator, TypeVar
_T = TypeVar("_T")
# https://docs.python.org/3/library/itertools.html#itertools-recipes
def grouper(iterable: Iterable[_T], n: int, fillvalue: _T = None) -> Iterator[_T]:
"Collect data into fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)