def lasts(iterable, items=1, default=None):
# type: (Iterable[T], int, T) -> Iterable[T]
""" Lazily return the last x items from this iterable or default. """
last_items = deque(iterable, maxlen=items)
for _ in range(items - len(last_items)):
yield default
for y in last_items:
yield y
# reduce is technically the last value of accumulate
# use ww.utils.EMPTY instead of EMPTY
# Put in the doc than scan=fold=accumulare and reduce=accumulate
# replace https://docs.python.org/3/library/itertools.html#itertools.accumulate
# that works only on Python 3.3 and doesn't have echo_start
# def accumulate(func, iterable, start=ww.utils.EMPTY, *, echo_start=True):
# """
# Scan higher-order function.
# The first 3 positional arguments are alike to the ``functools.reduce``
# signature. This function accepts an extra optional ``echo_start``
# parameter that controls whether the first value should be in the output.
# """
# it = iter(iterable)
# if start is ww.utils._EMPTY:
# start = next(it)
# if echo_start:
# yield start
# for item in it:
# start = func(start, item)
# yield start
评论列表
文章目录