pyiter.list_like

 1from typing import Any, Callable, Iterable, List, Union, overload
 2from .sequence import Sequence
 3from .transform import T, new_transform
 4
 5
 6class ListLike(List[T], Sequence[T]):
 7    def __init__(self, iterable: Iterable[T] = []):
 8        super().__init__(iterable)
 9        self.__transform__ = new_transform(iterable)
10
11    @overload
12    def count(self) -> int: ...
13    @overload
14    def count(self, predicate: Callable[[T], bool]) -> int: ...
15    @overload
16    def count(self, predicate: Callable[[T, int], bool]) -> int: ...
17    @overload
18    def count(self, predicate: Callable[[T, int, Sequence[T]], bool]) -> int: ...
19    def count(self, predicate: Union[Callable[..., bool], Any, None] = None) -> int:
20        """
21        Returns the number of elements in the Sequence that satisfy the specified [predicate] function.
22
23        Example 1:
24        >>> lst = [1, 2, 3]
25        >>> it(lst).count()
26        3
27        >>> it(lst).count(lambda x: x > 0)
28        3
29        >>> it(lst).count(lambda x: x > 2)
30        1
31        """
32        if predicate is None:
33            return len(self)
34        predicate = self.__callback_overload_warpper__(predicate)
35        return sum(1 for i in self if predicate(i))
class ListLike(typing.List[~T], pyiter.sequence.Sequence[~T]):
 7class ListLike(List[T], Sequence[T]):
 8    def __init__(self, iterable: Iterable[T] = []):
 9        super().__init__(iterable)
10        self.__transform__ = new_transform(iterable)
11
12    @overload
13    def count(self) -> int: ...
14    @overload
15    def count(self, predicate: Callable[[T], bool]) -> int: ...
16    @overload
17    def count(self, predicate: Callable[[T, int], bool]) -> int: ...
18    @overload
19    def count(self, predicate: Callable[[T, int, Sequence[T]], bool]) -> int: ...
20    def count(self, predicate: Union[Callable[..., bool], Any, None] = None) -> int:
21        """
22        Returns the number of elements in the Sequence that satisfy the specified [predicate] function.
23
24        Example 1:
25        >>> lst = [1, 2, 3]
26        >>> it(lst).count()
27        3
28        >>> it(lst).count(lambda x: x > 0)
29        3
30        >>> it(lst).count(lambda x: x > 2)
31        1
32        """
33        if predicate is None:
34            return len(self)
35        predicate = self.__callback_overload_warpper__(predicate)
36        return sum(1 for i in self if predicate(i))

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.