Exemplo n.º 1
0
 def max_items(
     self,
     *,
     key: _max_min_key_annotation = _max_min_key_default,
     default: Union[_T, Sentinel] = sentinel,
 ) -> _T:
     _, kwargs = drop_sentinel(key=key, default=default)
     return max(self.items(), **kwargs)
Exemplo n.º 2
0
 def islice(
     self,
     start: int,
     stop: Union[int, Sentinel] = sentinel,
     step: Union[int, Sentinel] = sentinel,
 ) -> "ChainedIterable[_T]":
     args, _ = drop_sentinel(stop, step)
     return self.pipe(islice, start, *args, index=0)
Exemplo n.º 3
0
 def range(
     cls: Type["ChainedIterable"],
     start: int,
     stop: Union[int, Sentinel] = sentinel,
     step: Union[int, Sentinel] = sentinel,
 ) -> "ChainedIterable[int]":
     args, _ = drop_sentinel(stop, step)
     return cls(range(start, *args))
Exemplo n.º 4
0
def test_range(
    start: int, stop: Union[int, Sentinel], step: Union[int, Sentinel],
) -> None:
    if step is sentinel:
        assume(stop is not sentinel)
    args, _ = drop_sentinel(stop, step)
    iterable = ChainedIterable.range(start, *args)
    assert isinstance(iterable, ChainedIterable)
    assert iterable == range(start, *args)
Exemplo n.º 5
0
 def reduce(
     self,
     func: Callable[[_T, _T], _T],
     initial: Union[_U, Sentinel] = sentinel,
 ) -> Any:
     args, _ = drop_sentinel(initial)
     try:
         return reduce(func, self._iterable, *args)
     except TypeError as error:
         (msg,) = error.args
         if msg == "reduce() of empty sequence with no initial value":
             raise EmptyIterableError from None
         else:
             raise error
Exemplo n.º 6
0
 def sum(self, start: Union[_T, int] = 0) -> Union[_T, int]:
     args, _ = drop_sentinel(start)
     return sum(self._iterable, *args)
 def sum(self, start: Union[_T, Sentinel] = sentinel) -> _T:
     args, _ = drop_sentinel(start)
     return sum(self._iterable, *args)