From 94b7988c1e692d35807f7cb754159c52dea19261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Fr=C4=85cek?= Date: Mon, 13 Nov 2023 10:50:07 +0100 Subject: [PATCH] pypi version bump --- pyproject.toml | 2 +- site/eager/index.html | 646 +++++++++++++++++++----------------------- site/qlist/index.html | 425 ++++++++++++++------------- site/sitemap.xml.gz | Bin 127 -> 127 bytes src/qwlist/eager.py | 101 ++++--- src/qwlist/qwlist.py | 81 +++--- tests/eager.py | 203 +++++++++++++ tests/test_qwlist.py | 7 +- 8 files changed, 823 insertions(+), 642 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 21c4aef..55ec072 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "qwlist" -version = "0.1.7" +version = "0.1.8" authors = [ { name="Witold FrÄ…cek" }, ] diff --git a/site/eager/index.html b/site/eager/index.html index 910a84f..922873e 100644 --- a/site/eager/index.html +++ b/site/eager/index.html @@ -346,19 +346,6 @@ flatmap() - -
  • @@ -373,19 +360,6 @@ fold() - -
  • @@ -393,19 +367,6 @@ fold_right() - -
  • @@ -509,19 +470,6 @@ flatmap() - -
  • @@ -536,19 +484,6 @@ fold() - -
  • @@ -556,19 +491,6 @@ fold_right() - -
  • @@ -639,6 +561,9 @@

    EagerQList

    Bases: list

    + +

    EagerQList is a python list extension that adds several chainable, methods to the standard list.

    +

    Found in qwlist.eager.EagerQList

    Source code in src\qwlist\eager.py @@ -814,7 +739,19 @@

    EagerQList

    177 178 179 -180
    class EagerQList(list):
    +180
    +181
    +182
    +183
    +184
    +185
    +186
    +187
    class EagerQList(list):
    +    """
    +    `EagerQList` is a python list extension that adds several chainable, methods to the standard `list`.
    +
    +    Found in `qwlist.eager.EagerQList`
    +    """
         @overload
         def __getitem__(self, item: int) -> T:
             ...
    @@ -830,76 +767,80 @@ 

    EagerQList

    def list(self) -> list[T]: """ - Changes EagerQList into list. + Changes `EagerQList` into `list`. - Returns: list[T] + Returns: `list[T]` """ return list(self) def qlist(self) -> "QList[T]": """ - Changes EagerQList into Qlist. + Changes `EagerQList` into `Qlist`. - Returns: QList[T] + Returns: `QList[T]` """ - from qwlist.qwlist import QList + from qwlist import QList return QList(self) def filter(self, pred: Callable[[T], bool]) -> "EagerQList[T]": """ - Returns a EagerQList containing all values from this EagerQList for which + Returns an `EagerQList` containing all values from this `EagerQList` for which the predicate holds true. Args: - pred: function (T) -> bool - Returns: EagerQList[T] + pred: `function (T) -> bool` + + Returns: `EagerQList[T]` + + Examples: + >>> EagerQList([1, 2, 3, 4]).filter(lambda x: x < 3) + [1, 2] """ return EagerQList(elem for elem in self if pred(elem)) def map(self, mapper: Callable[[T], K]) -> "EagerQList[K]": """ - Returns a EagerQList containing all values from this EagerQList with + Returns an `EagerQList` containing all values from this `EagerQList` with the mapping function applied on them. Args: - mapper: function: (T) -> K + mapper: `function: (T) -> K` - Returns: EagerQList[K] + Returns: `EagerQList[K]` """ return EagerQList(mapper(elem) for elem in self) def foreach(self, action: Callable[[T], None]): """ - Applies the given function to each of the EagerQList elements. + Applies the given function to each of the `EagerQList` elements. Args: - action: function (T) -> None + action: `function (T) -> None` - Returns: None + Returns: `None` """ for elem in self: action(elem) def fold(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the EagerQList by processing + Given the combination operator reduces the `EagerQList` by processing its values, building up the final value. **Other names:** fold_left, reduce, accumulate, aggregate Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the given combination operator on each element of the EagerQList, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` - Examples - -------- - >>> s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) - 6 + Examples: + >>> s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) + 6 """ acc = init for elem in self: @@ -908,22 +849,21 @@

    EagerQList

    def fold_right(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the EagerQList by processing + Given the combination operator reduces the `EagerQList` by processing its values, building up the final value. Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the given combination operator on each element of the QList, starting from the last element, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` - Examples - -------- - >>> s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) - 6 + Examples: + >>> s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) + 6 """ acc = init for elem in self[::-1]: @@ -935,53 +875,52 @@

    EagerQList

    def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> "EagerQList[K]": """ - Applies the mapper function to each element of the EagerQList and flattens the results. + Applies the mapper function to each element of the `EagerQList` and flattens the results. Args: - mapper: function (T) -> Iterable[K] + mapper: `function (T) -> Iterable[K]` - Returns: EagerQList[K] + Returns: `EagerQList[K]` Examples: - -------- - >>> EagerQList([1, 2]).flatmap(lambda x: [x, x]) - [1, 1, 2, 2] + >>> EagerQList([1, 2]).flatmap(lambda x: [x, x]) + [1, 1, 2, 2] """ return EagerQList(x for elem in self for x in mapper(elem)) def zip(self, other: Iterable[K]) -> "EagerQList[tuple[T, K]]": """ - Combines this EagerQList with the given Iterable elementwise as tuples. - The returned EagerQList objects has at most the number of elements of - the shorter sequence (self or Iterable). + Combines this `EagerQList` with the given `Iterable` elementwise as tuples. + The returned `EagerQList` objects has at most the number of elements of + the shorter sequence (`self` or `Iterable`). Args: - other: iterable to zip with this EagerQList. + other: iterable to zip with this `EagerQList`. - Returns: EagerQList[tuple[T, K]] + Returns: `EagerQList[tuple[T, K]]` """ return EagerQList(zip(self, other)) - def sorted(self, key: Callable[[T], SupportsLessThan] = lambda x: x, reverse: bool = False) -> "EagerQList[T]": + def sorted(self, key: Callable[[T], SupportsLessThan] = None, reverse: bool = False) -> "EagerQList[T]": """ - Returns a new EagerQList containing all items from the original list in ascending order. + Returns a new `EagerQList` containing all items from the original list in ascending order. A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order. Args: - key: function (T) -> SupportsLessThan. Defaults to identity function (x: T) -> x - reverse: if set to True sorts values in descending order. Defaults to False + key: `function (T) -> SupportsLessThan`. Defaults to `None` + reverse: if set to `True` sorts values in descending order. Defaults to `False` - Returns: EagerQList[T] + Returns: `EagerQList[T]` """ return EagerQList(sorted(self, key=key, reverse=reverse)) def flatten(self) -> "EagerQList[T]": """ - If self is a EagerQList of Iterable[T] flatten concatenates all iterables into a - single list and returns a new EagerQList[T]. - Returns: EagerQList[T] + If self is a `EagerQList` of `Iterable[T]` flatten concatenates all iterables into a + single list and returns a new `EagerQList[T]`. + Returns: `EagerQList[T]` """ def inner(): for elem in self: @@ -1016,7 +955,7 @@

    -

    Returns a EagerQList containing all values from this EagerQList for which +

    Returns an EagerQList containing all values from this EagerQList for which the predicate holds true.

    @@ -1039,7 +978,7 @@

    -

    function (T) -> bool

    +

    function (T) -> bool

    @@ -1048,27 +987,44 @@

    -

    Returns: EagerQList[T]

    +

    Returns: EagerQList[T]

    + + + +

    Examples:

    +
    >>> EagerQList([1, 2, 3, 4]).filter(lambda x: x < 3)
    +[1, 2]
    +
    Source code in src\qwlist\eager.py -
    39
    -40
    -41
    -42
    -43
    -44
    +            
    44
     45
     46
     47
    -48
    def filter(self, pred: Callable[[T], bool]) -> "EagerQList[T]":
    +48
    +49
    +50
    +51
    +52
    +53
    +54
    +55
    +56
    +57
    +58
    def filter(self, pred: Callable[[T], bool]) -> "EagerQList[T]":
         """
    -    Returns a EagerQList containing all values from this EagerQList for which
    +    Returns an `EagerQList` containing all values from this `EagerQList` for which
         the predicate holds true.
     
         Args:
    -         pred: function (T) -> bool
    -    Returns: EagerQList[T]
    +         pred: `function (T) -> bool`
    +
    +    Returns: `EagerQList[T]`
    +
    +    Examples:
    +        >>> EagerQList([1, 2, 3, 4]).filter(lambda x: x < 3)
    +        [1, 2]
         """
         return EagerQList(elem for elem in self if pred(elem))
     
    @@ -1091,7 +1047,7 @@

    -

    Applies the mapper function to each element of the EagerQList and flattens the results.

    +

    Applies the mapper function to each element of the EagerQList and flattens the results.

    @@ -1113,7 +1069,7 @@

    -

    function (T) -> Iterable[K]

    +

    function (T) -> Iterable[K]

    @@ -1122,46 +1078,42 @@

    -

    Returns: EagerQList[K]

    -

    Examples:

    -
    -
    -
    -

    EagerQList([1, 2]).flatmap(lambda x: [x, x]) -[1, 1, 2, 2]

    -
    -
    -
    +

    Returns: EagerQList[K]

    + + + +

    Examples:

    +
    >>> EagerQList([1, 2]).flatmap(lambda x: [x, x])
    +[1, 1, 2, 2]
    +
    Source code in src\qwlist\eager.py -
    127
    -128
    -129
    -130
    -131
    -132
    -133
    -134
    -135
    +            
    135
     136
     137
     138
     139
     140
    -141
    def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> "EagerQList[K]":
    +141
    +142
    +143
    +144
    +145
    +146
    +147
    +148
    def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> "EagerQList[K]":
         """
    -    Applies the mapper function to each element of the EagerQList and flattens the results.
    +    Applies the mapper function to each element of the `EagerQList` and flattens the results.
     
         Args:
    -        mapper: function (T) -> Iterable[K]
    +        mapper: `function (T) -> Iterable[K]`
     
    -    Returns: EagerQList[K]
    +    Returns: `EagerQList[K]`
     
         Examples:
    -    --------
    -    >>> EagerQList([1, 2]).flatmap(lambda x: [x, x])
    -    [1, 1, 2, 2]
    +        >>> EagerQList([1, 2]).flatmap(lambda x: [x, x])
    +        [1, 1, 2, 2]
         """
         return EagerQList(x for elem in self for x in mapper(elem))
     
    @@ -1184,26 +1136,26 @@

    -

    If self is a EagerQList of Iterable[T] flatten concatenates all iterables into a -single list and returns a new EagerQList[T]. -Returns: EagerQList[T]

    +

    If self is a EagerQList of Iterable[T] flatten concatenates all iterables into a +single list and returns a new EagerQList[T]. +Returns: EagerQList[T]

    Source code in src\qwlist\eager.py -
    171
    -172
    -173
    -174
    -175
    -176
    -177
    -178
    +            
    178
     179
    -180
    def flatten(self) -> "EagerQList[T]":
    +180
    +181
    +182
    +183
    +184
    +185
    +186
    +187
    def flatten(self) -> "EagerQList[T]":
         """
    -    If self is a EagerQList of Iterable[T] flatten concatenates all iterables into a
    -    single list and returns a new EagerQList[T].
    -    Returns: EagerQList[T]
    +    If self is a `EagerQList` of `Iterable[T]` flatten concatenates all iterables into a
    +    single list and returns a new `EagerQList[T]`.
    +    Returns: `EagerQList[T]`
         """
         def inner():
             for elem in self:
    @@ -1229,7 +1181,7 @@ 

    -

    Given the combination operator reduces the EagerQList by processing +

    Given the combination operator reduces the EagerQList by processing its values, building up the final value.

    Other names: fold_left, reduce, accumulate, aggregate

    @@ -1253,7 +1205,7 @@

    -

    function: (K, T) -> K +

    function: (K, T) -> K Given the initial value init applies the given combination operator on each element of the EagerQList, treating the result as a first argument in the next step.

    @@ -1279,63 +1231,59 @@

    -

    Returns: K

    -

    Examples

    -
    -
    -
    -

    s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) -6

    -
    -
    -
    +

    Returns: K

    + + + +

    Examples:

    +
    >>> s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0)
    +6
    +
    Source code in src\qwlist\eager.py -
    74
    -75
    -76
    -77
    -78
    -79
    -80
    -81
    -82
    -83
    -84
    -85
    -86
    -87
    -88
    -89
    -90
    -91
    -92
    -93
    -94
    -95
    -96
    -97
    -98
    def fold(self, operation: Callable[[K, T], K], init: K) -> K:
    +            
     84
    + 85
    + 86
    + 87
    + 88
    + 89
    + 90
    + 91
    + 92
    + 93
    + 94
    + 95
    + 96
    + 97
    + 98
    + 99
    +100
    +101
    +102
    +103
    +104
    +105
    +106
    +107
    def fold(self, operation: Callable[[K, T], K], init: K) -> K:
         """
    -    Given the combination operator reduces the EagerQList by processing
    +    Given the combination operator reduces the `EagerQList` by processing
         its values, building up the final value.
     
         **Other names:** fold_left, reduce, accumulate, aggregate
     
         Args:
    -        operation: function: (K, T) -> K
    +        operation: `function: (K, T) -> K`
                 Given the initial value `init` applies the
                 given combination operator on each element of the EagerQList,
                 treating the result as a first argument in the next step.
             init: initial value for the combination operator.
     
    -    Returns: K
    +    Returns: `K`
     
    -    Examples
    -    --------
    -    >>> s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0)
    -    6
    +    Examples:
    +        >>> s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0)
    +        6
         """
         acc = init
         for elem in self:
    @@ -1361,7 +1309,7 @@ 

    -

    Given the combination operator reduces the EagerQList by processing +

    Given the combination operator reduces the EagerQList by processing its values, building up the final value.

    @@ -1384,7 +1332,7 @@

    -

    function: (K, T) -> K +

    function: (K, T) -> K Given the initial value init applies the given combination operator on each element of the QList, starting from the last element, treating the result as a first argument in the next step.

    @@ -1410,29 +1358,18 @@

    -

    Returns: K

    -

    Examples

    -
    -
    -
    -

    s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) -6

    -
    -
    -
    +

    Returns: K

    + + + +

    Examples:

    +
    >>> s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0)
    +6
    +
    Source code in src\qwlist\eager.py -
    100
    -101
    -102
    -103
    -104
    -105
    -106
    -107
    -108
    -109
    +            
    109
     110
     111
     112
    @@ -1445,24 +1382,31 @@ 

    Examples

    119 120 121 -122
    def fold_right(self, operation: Callable[[K, T], K], init: K) -> K:
    +122
    +123
    +124
    +125
    +126
    +127
    +128
    +129
    +130
    def fold_right(self, operation: Callable[[K, T], K], init: K) -> K:
         """
    -    Given the combination operator reduces the EagerQList by processing
    +    Given the combination operator reduces the `EagerQList` by processing
         its values, building up the final value.
     
         Args:
    -        operation: function: (K, T) -> K
    +        operation: `function: (K, T) -> K`
                 Given the initial value `init` applies the
                 given combination operator on each element of the QList, starting from the
                 last element, treating the result as a first argument in the next step.
             init: initial value for the combination operator.
     
    -    Returns: K
    +    Returns: `K`
     
    -    Examples
    -    --------
    -    >>> s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0)
    -    6
    +    Examples:
    +        >>> s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0)
    +        6
         """
         acc = init
         for elem in self[::-1]:
    @@ -1488,7 +1432,7 @@ 

    -

    Applies the given function to each of the EagerQList elements.

    +

    Applies the given function to each of the EagerQList elements.

    @@ -1510,7 +1454,7 @@

    -

    function (T) -> None

    +

    function (T) -> None

    @@ -1519,28 +1463,28 @@

    -

    Returns: None

    +

    Returns: None

    Source code in src\qwlist\eager.py -
    62
    -63
    -64
    -65
    -66
    -67
    -68
    -69
    -70
    -71
    -72
    def foreach(self, action: Callable[[T], None]):
    +            
    72
    +73
    +74
    +75
    +76
    +77
    +78
    +79
    +80
    +81
    +82
    def foreach(self, action: Callable[[T], None]):
         """
    -    Applies the given function to each of the EagerQList elements.
    +    Applies the given function to each of the `EagerQList` elements.
     
         Args:
    -        action: function (T) -> None
    +        action: `function (T) -> None`
     
    -    Returns: None
    +    Returns: `None`
         """
         for elem in self:
             action(elem)
    @@ -1564,22 +1508,22 @@ 

    -

    Changes EagerQList into list.

    -

    Returns: list[T]

    +

    Changes EagerQList into list.

    +

    Returns: list[T]

    Source code in src\qwlist\eager.py -
    22
    -23
    -24
    -25
    -26
    -27
    -28
    def list(self) -> list[T]:
    +            
    27
    +28
    +29
    +30
    +31
    +32
    +33
    def list(self) -> list[T]:
         """
    -    Changes EagerQList into list.
    +    Changes `EagerQList` into `list`.
     
    -    Returns: list[T]
    +    Returns: `list[T]`
         """
         return list(self)
     
    @@ -1602,7 +1546,7 @@

    -

    Returns a EagerQList containing all values from this EagerQList with +

    Returns an EagerQList containing all values from this EagerQList with the mapping function applied on them.

    @@ -1625,7 +1569,7 @@

    -

    function: (T) -> K

    +

    function: (T) -> K

    @@ -1634,29 +1578,29 @@

    -

    Returns: EagerQList[K]

    +

    Returns: EagerQList[K]

    Source code in src\qwlist\eager.py -
    50
    -51
    -52
    -53
    -54
    -55
    -56
    -57
    -58
    -59
    -60
    def map(self, mapper: Callable[[T], K]) -> "EagerQList[K]":
    +            
    60
    +61
    +62
    +63
    +64
    +65
    +66
    +67
    +68
    +69
    +70
    def map(self, mapper: Callable[[T], K]) -> "EagerQList[K]":
         """
    -    Returns a EagerQList containing all values from this EagerQList with
    +    Returns an `EagerQList` containing all values from this `EagerQList` with
         the mapping function applied on them.
     
         Args:
    -        mapper: function: (T) -> K
    +        mapper: `function: (T) -> K`
     
    -    Returns: EagerQList[K]
    +    Returns: `EagerQList[K]`
         """
         return EagerQList(mapper(elem) for elem in self)
     
    @@ -1679,25 +1623,25 @@

    -

    Changes EagerQList into Qlist.

    -

    Returns: QList[T]

    +

    Changes EagerQList into Qlist.

    +

    Returns: QList[T]

    Source code in src\qwlist\eager.py -
    @@ -1757,7 +1701,7 @@

    30
    -31
    -32
    -33
    -34
    -35
    +            
    35
     36
    -37
    def qlist(self) -> "QList[T]":
    +37
    +38
    +39
    +40
    +41
    +42
    def qlist(self) -> "QList[T]":
         """
    -    Changes EagerQList into Qlist.
    +    Changes `EagerQList` into `Qlist`.
     
    -    Returns: QList[T]
    +    Returns: `QList[T]`
         """
    -    from qwlist.qwlist import QList
    +    from qwlist import QList
         return QList(self)
     
    @@ -1712,14 +1656,14 @@

    - sorted(key=lambda : x, reverse=False) + sorted(key=None, reverse=False)

    -

    Returns a new EagerQList containing all items from the original list in ascending order.

    +

    Returns a new EagerQList containing all items from the original list in ascending order.

    A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order.

    @@ -1743,11 +1687,11 @@

    -

    function (T) -> SupportsLessThan. Defaults to identity function (x: T) -> x

    +

    function (T) -> SupportsLessThan. Defaults to None

    - lambda : x + None
    -

    if set to True sorts values in descending order. Defaults to False

    +

    if set to True sorts values in descending order. Defaults to False

    @@ -1766,35 +1710,35 @@

    -

    Returns: EagerQList[T]

    +

    Returns: EagerQList[T]

    Source code in src\qwlist\eager.py -
    156
    -157
    -158
    -159
    -160
    -161
    -162
    -163
    +            
    163
     164
     165
     166
     167
     168
    -169
    def sorted(self, key: Callable[[T], SupportsLessThan] = lambda x: x, reverse: bool = False) -> "EagerQList[T]":
    +169
    +170
    +171
    +172
    +173
    +174
    +175
    +176
    def sorted(self, key: Callable[[T], SupportsLessThan] = None, reverse: bool = False) -> "EagerQList[T]":
         """
    -    Returns a new EagerQList containing all items from the original list in ascending order.
    +    Returns a new `EagerQList` containing all items from the original list in ascending order.
     
         A custom key function can be supplied to customize the sort order, and the reverse
         flag can be set to request the result in descending order.
     
         Args:
    -        key: function (T) -> SupportsLessThan. Defaults to identity function (x: T) -> x
    -        reverse: if set to True sorts values in descending order. Defaults to False
    +        key: `function (T) -> SupportsLessThan`. Defaults to `None`
    +        reverse: if set to `True` sorts values in descending order. Defaults to `False`
     
    -    Returns: EagerQList[T]
    +    Returns: `EagerQList[T]`
         """
         return EagerQList(sorted(self, key=key, reverse=reverse))
     
    @@ -1817,9 +1761,9 @@

    -

    Combines this EagerQList with the given Iterable elementwise as tuples. - The returned EagerQList objects has at most the number of elements of - the shorter sequence (self or Iterable).

    +

    Combines this EagerQList with the given Iterable elementwise as tuples. + The returned EagerQList objects has at most the number of elements of + the shorter sequence (self or Iterable).

    @@ -1841,7 +1785,7 @@

    -

    iterable to zip with this EagerQList.

    +

    iterable to zip with this EagerQList.

    @@ -1850,31 +1794,31 @@

    -

    Returns: EagerQList[tuple[T, K]]

    +

    Returns: EagerQList[tuple[T, K]]

    Source code in src\qwlist\eager.py -
    143
    -144
    -145
    -146
    -147
    -148
    -149
    -150
    +            
    150
     151
     152
     153
    -154
    def zip(self, other: Iterable[K]) -> "EagerQList[tuple[T, K]]":
    +154
    +155
    +156
    +157
    +158
    +159
    +160
    +161
    def zip(self, other: Iterable[K]) -> "EagerQList[tuple[T, K]]":
         """
    -    Combines this EagerQList with the given Iterable elementwise as tuples.
    -     The returned EagerQList objects has at most the number of elements of
    -     the shorter sequence (self or Iterable).
    +    Combines this `EagerQList` with the given `Iterable` elementwise as tuples.
    +     The returned `EagerQList` objects has at most the number of elements of
    +     the shorter sequence (`self` or `Iterable`).
     
         Args:
    -        other: iterable to zip with this EagerQList.
    +        other: iterable to zip with this `EagerQList`.
     
    -    Returns: EagerQList[tuple[T, K]]
    +    Returns: `EagerQList[tuple[T, K]]`
         """
         return EagerQList(zip(self, other))
     
    diff --git a/site/qlist/index.html b/site/qlist/index.html index 4ec1289..84efde5 100644 --- a/site/qlist/index.html +++ b/site/qlist/index.html @@ -635,7 +635,7 @@

    QList

    QList is a python list extension that adds several chainable, lazy -evaluated methods to the standard 'list'.

    +evaluated methods to the standard list.

    Found in qwlist.QList

    @@ -912,10 +912,15 @@

    QList

    517 518 519 -520
    class QList(list):
    +520
    +521
    +522
    +523
    +524
    +525
    class QList(list):
         """
         `QList` is a python list extension that adds several chainable, lazy
    -    evaluated methods to the standard 'list'.
    +    evaluated methods to the standard `list`.
     
         Found in `qwlist.QList`
         """
    @@ -935,13 +940,13 @@ 

    QList

    def slice(self, s: slice) -> Lazy[T]: """ - Calling this method with `slice(3)` works similarly to + Calling this method with `s` equal to `slice(3)` works similarly to `list[:3]` but is lazy evaluated. Args: s: slice object - Returns: Lazy[T] + Returns: `Lazy[T]` """ assert isinstance(s, slice), f"slice method argument must be a slice object. Got {type(s)}." @@ -952,29 +957,34 @@

    QList

    def list(self) -> list[T]: """ - Changes QList into list. + Changes `QList` into `list`. - Returns: list[T] + Returns: `list[T]` """ return list(self) def eager(self) -> "EagerQList[T]": """ - Changes QList into EagerQList. + Changes `QList` into `EagerQList`. - Returns: EagerQList[T] + Returns: `EagerQList[T]` """ from .eager import EagerQList return EagerQList(self) def filter(self, pred: Callable[[T], bool]) -> Lazy[T]: """ - Returns a Lazy object containing all values from the QList for which + Returns a `Lazy` object containing all values from the `QList` for which the predicate holds true. Args: - pred: function (T) -> bool - Returns: Lazy[T] + pred: `function (T) -> bool` + + Returns: `Lazy[T]` + + Examples: + >>> QList([1, 2, 3, 4]).filter(lambda x: x < 3).collect() + [1, 2] """ def inner(): for elem in self: @@ -984,13 +994,13 @@

    QList

    def map(self, mapper: Callable[[T], K]) -> Lazy[K]: """ - Returns a Lazy object containing all values from QList with + Returns a `Lazy` object containing all values from `QList` with the mapping function applied on them. Args: - mapper: function: (T) -> K + mapper: `function: (T) -> K` - Returns: Lazy[K] + Returns: `Lazy[K]` """ def inner(): for elem in self: @@ -999,31 +1009,31 @@

    QList

    def foreach(self, action: Callable[[T], None]): """ - Applies the given function to each of the QList elements. + Applies the given function to each of the `QList` elements. Args: - action: function (T) -> None + action: `function (T) -> None` - Returns: None + Returns: `None` """ for elem in self: action(elem) def fold(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the QList by processing + Given the combination operator reduces the `QList` by processing its values, building up the final value. **Other names:** fold_left, reduce, accumulate, aggregate Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the - given combination operator on each element of the QList, + given combination operator on each element of the `QList`, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` Examples: >>> QList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) @@ -1036,17 +1046,17 @@

    QList

    def fold_right(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the QList by processing + Given the combination operator reduces the `QList` by processing its values, building up the final value. Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the - given combination operator on each element of the QList, starting from the + given combination operator on each element of the `QList`, starting from the last element, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` Examples: >>> QList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) @@ -1059,9 +1069,9 @@

    QList

    def len(self) -> int: """ - Returns the len of the QList + Returns the len of the `QList` - (time complexity: O(1)) + (time complexity: `O(1)`) Returns: int """ @@ -1069,12 +1079,12 @@

    QList

    def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> Lazy[K]: """ - Applies the mapper function to each element of the QList and flattens the results. + Applies the mapper function to each element of the `QList` and flattens the results. Args: - mapper: function (T) -> Iterable[K] + mapper: `function (T) -> Iterable[K]` - Returns: Lazy[K] + Returns: `Lazy[K]` Examples: >>> QList([1, 2]).flatmap(lambda x: [x, x]).qlist() @@ -1087,29 +1097,29 @@

    QList

    def zip(self, other: Iterable[K]) -> Lazy[tuple[T, K]]: """ - Combines this QList with the given Iterable elementwise as tuples. - The returned Lazy objects yields at most the number of elements of - the shorter sequence (self or Iterable). + Combines this `QList` with the given `Iterable` elementwise as tuples. + The returned `Lazy` objects yields at most the number of elements of + the shorter sequence (`self` or `Iterable`). Args: - other: iterable to zip with this QList. + other: iterable to zip with this `QList`. - Returns: Lazy[tuple[T, K]] + Returns: `Lazy[tuple[T, K]]` """ return Lazy(zip(self, other)) def sorted(self, key: Callable[[T], SupportsLessThan] = None, reverse: bool = False) -> "QList[T]": """ - Returns a new QList containing all items from the original list in ascending order. + Returns a new `QList` containing all items from the original list in ascending order. A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order. Args: - key: function (T) -> SupportsLessThan. Defaults to None - reverse: if set to True sorts values in descending order. Defaults to False + key: `function (T) -> SupportsLessThan`. Defaults to `None` + reverse: if set to `True` sorts values in descending order. Defaults to `False` - Returns: QList[T] + Returns: `QList[T]` """ return QList(sorted(self, key=key, reverse=reverse)) @@ -1229,12 +1239,7 @@

    Source code in src\qwlist\qwlist.py -
    499
    -500
    -501
    -502
    -503
    -504
    +            
    504
     505
     506
     507
    @@ -1250,7 +1255,12 @@ 

    517 518 519 -520

    def cycle(self):
    +520
    +521
    +522
    +523
    +524
    +525
    def cycle(self):
         """
         Returns a Lazy[T] that cycles through the elements of the QList that means
         on achieving the last element the iteration starts from the beginning. The
    @@ -1292,8 +1302,8 @@ 

    -

    Changes QList into EagerQList.

    -

    Returns: EagerQList[T]

    +

    Changes QList into EagerQList.

    +

    Returns: EagerQList[T]

    Source code in src\qwlist\qwlist.py @@ -1306,9 +1316,9 @@

    300 301

    def eager(self) -> "EagerQList[T]":
         """
    -    Changes QList into EagerQList.
    +    Changes `QList` into `EagerQList`.
     
    -    Returns: EagerQList[T]
    +    Returns: `EagerQList[T]`
         """
         from .eager import EagerQList
         return EagerQList(self)
    @@ -1332,7 +1342,7 @@ 

    -

    Returns a Lazy object containing all values from the QList for which +

    Returns a Lazy object containing all values from the QList for which the predicate holds true.

    @@ -1355,7 +1365,7 @@

    -

    function (T) -> bool

    +

    function (T) -> bool

    @@ -1364,7 +1374,14 @@

    -

    Returns: Lazy[T]

    +

    Returns: Lazy[T]

    + + + +

    Examples:

    +
    >>> QList([1, 2, 3, 4]).filter(lambda x: x < 3).collect()
    +[1, 2]
    +
    Source code in src\qwlist\qwlist.py @@ -1381,14 +1398,24 @@

    313 314 315 -316

    def filter(self, pred: Callable[[T], bool]) -> Lazy[T]:
    +316
    +317
    +318
    +319
    +320
    +321
    def filter(self, pred: Callable[[T], bool]) -> Lazy[T]:
         """
    -    Returns a Lazy object containing all values from the QList for which
    +    Returns a `Lazy` object containing all values from the `QList` for which
         the predicate holds true.
     
         Args:
    -         pred: function (T) -> bool
    -    Returns: Lazy[T]
    +         pred: `function (T) -> bool`
    +
    +    Returns: `Lazy[T]`
    +
    +    Examples:
    +        >>> QList([1, 2, 3, 4]).filter(lambda x: x < 3).collect()
    +        [1, 2]
         """
         def inner():
             for elem in self:
    @@ -1415,7 +1442,7 @@ 

    -

    Applies the mapper function to each element of the QList and flattens the results.

    +

    Applies the mapper function to each element of the QList and flattens the results.

    @@ -1437,7 +1464,7 @@

    -

    function (T) -> Iterable[K]

    +

    function (T) -> Iterable[K]

    @@ -1446,7 +1473,7 @@

    -

    Returns: Lazy[K]

    +

    Returns: Lazy[K]

    @@ -1457,12 +1484,7 @@

    Source code in src\qwlist\qwlist.py -
    403
    -404
    -405
    -406
    -407
    -408
    +            
    408
     409
     410
     411
    @@ -1473,14 +1495,19 @@ 

    416 417 418 -419

    def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> Lazy[K]:
    +419
    +420
    +421
    +422
    +423
    +424
    def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> Lazy[K]:
         """
    -    Applies the mapper function to each element of the QList and flattens the results.
    +    Applies the mapper function to each element of the `QList` and flattens the results.
     
         Args:
    -        mapper: function (T) -> Iterable[K]
    +        mapper: `function (T) -> Iterable[K]`
     
    -    Returns: Lazy[K]
    +    Returns: `Lazy[K]`
     
         Examples:
             >>> QList([1, 2]).flatmap(lambda x: [x, x]).qlist()
    @@ -1516,16 +1543,16 @@ 

    Source code in src\qwlist\qwlist.py -
    488
    -489
    -490
    -491
    -492
    -493
    +            
    @@ -1605,7 +1632,7 @@

    493
     494
     495
     496
    -497
    def flatten(self) -> Lazy[T]:
    +497
    +498
    +499
    +500
    +501
    +502
    def flatten(self) -> Lazy[T]:
         """
         If self is a QList of Iterable[T] flatten concatenates all iterables into a
         single list and returns a Lazy[T] object
    @@ -1555,7 +1582,7 @@ 

    -

    Given the combination operator reduces the QList by processing +

    Given the combination operator reduces the QList by processing its values, building up the final value.

    Other names: fold_left, reduce, accumulate, aggregate

    @@ -1579,9 +1606,9 @@

    -

    function: (K, T) -> K +

    function: (K, T) -> K Given the initial value init applies the -given combination operator on each element of the QList, +given combination operator on each element of the QList, treating the result as a first argument in the next step.

    -

    Returns: K

    +

    Returns: K

    @@ -1616,12 +1643,7 @@

    Source code in src\qwlist\qwlist.py -
    345
    -346
    -347
    -348
    -349
    -350
    +            
    @@ -1732,7 +1759,7 @@

    350
     351
     352
     353
    @@ -1639,21 +1661,26 @@ 

    365 366 367 -368

    def fold(self, operation: Callable[[K, T], K], init: K) -> K:
    +368
    +369
    +370
    +371
    +372
    +373
    def fold(self, operation: Callable[[K, T], K], init: K) -> K:
         """
    -    Given the combination operator reduces the QList by processing
    +    Given the combination operator reduces the `QList` by processing
         its values, building up the final value.
     
         **Other names:** fold_left, reduce, accumulate, aggregate
     
         Args:
    -        operation: function: (K, T) -> K
    +        operation: `function: (K, T) -> K`
                 Given the initial value `init` applies the
    -            given combination operator on each element of the QList,
    +            given combination operator on each element of the `QList`,
                 treating the result as a first argument in the next step.
             init: initial value for the combination operator.
     
    -    Returns: K
    +    Returns: `K`
     
         Examples:
             >>> QList([1, 2, 3]).fold(lambda acc, x: acc + x, 0)
    @@ -1683,7 +1710,7 @@ 

    -

    Given the combination operator reduces the QList by processing +

    Given the combination operator reduces the QList by processing its values, building up the final value.

    @@ -1706,9 +1733,9 @@

    -

    function: (K, T) -> K +

    function: (K, T) -> K Given the initial value init applies the -given combination operator on each element of the QList, starting from the +given combination operator on each element of the QList, starting from the last element, treating the result as a first argument in the next step.

    -

    Returns: K

    +

    Returns: K

    @@ -1743,12 +1770,7 @@

    Source code in src\qwlist\qwlist.py -
    370
    -371
    -372
    -373
    -374
    -375
    +            
    375
     376
     377
     378
    @@ -1764,19 +1786,24 @@ 

    388 389 390 -391

    def fold_right(self, operation: Callable[[K, T], K], init: K) -> K:
    +391
    +392
    +393
    +394
    +395
    +396
    def fold_right(self, operation: Callable[[K, T], K], init: K) -> K:
         """
    -    Given the combination operator reduces the QList by processing
    +    Given the combination operator reduces the `QList` by processing
         its values, building up the final value.
     
         Args:
    -        operation: function: (K, T) -> K
    +        operation: `function: (K, T) -> K`
                 Given the initial value `init` applies the
    -            given combination operator on each element of the QList, starting from the
    +            given combination operator on each element of the `QList`, starting from the
                 last element, treating the result as a first argument in the next step.
             init: initial value for the combination operator.
     
    -    Returns: K
    +    Returns: `K`
     
         Examples:
             >>> QList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0)
    @@ -1806,7 +1833,7 @@ 

    -

    Applies the given function to each of the QList elements.

    +

    Applies the given function to each of the QList elements.

    @@ -1828,7 +1855,7 @@

    -

    function (T) -> None

    +

    function (T) -> None

    @@ -1837,28 +1864,28 @@

    -

    Returns: None

    +

    Returns: None

    Source code in src\qwlist\qwlist.py -
    333
    -334
    -335
    -336
    -337
    -338
    +            
    338
     339
     340
     341
     342
    -343
    def foreach(self, action: Callable[[T], None]):
    +343
    +344
    +345
    +346
    +347
    +348
    def foreach(self, action: Callable[[T], None]):
         """
    -    Applies the given function to each of the QList elements.
    +    Applies the given function to each of the `QList` elements.
     
         Args:
    -        action: function (T) -> None
    +        action: `function (T) -> None`
     
    -    Returns: None
    +    Returns: `None`
         """
         for elem in self:
             action(elem)
    @@ -1882,25 +1909,25 @@ 

    -

    Returns the len of the QList

    -

    (time complexity: O(1))

    +

    Returns the len of the QList

    +

    (time complexity: O(1))

    Returns: int

    Source code in src\qwlist\qwlist.py -
    393
    -394
    -395
    -396
    -397
    -398
    +            
    398
     399
     400
    -401
    def len(self) -> int:
    +401
    +402
    +403
    +404
    +405
    +406
    def len(self) -> int:
         """
    -    Returns the len of the QList
    +    Returns the len of the `QList`
     
    -    (time complexity: O(1))
    +    (time complexity: `O(1)`)
     
         Returns: int
         """
    @@ -1925,8 +1952,8 @@ 

    -

    Changes QList into list.

    -

    Returns: list[T]

    +

    Changes QList into list.

    +

    Returns: list[T]

    Source code in src\qwlist\qwlist.py @@ -1938,9 +1965,9 @@

    291 292

    def list(self) -> list[T]:
         """
    -    Changes QList into list.
    +    Changes `QList` into `list`.
     
    -    Returns: list[T]
    +    Returns: `list[T]`
         """
         return list(self)
     
    @@ -1963,7 +1990,7 @@

    -

    Returns a Lazy object containing all values from QList with +

    Returns a Lazy object containing all values from QList with the mapping function applied on them.

    @@ -1986,7 +2013,7 @@

    -

    function: (T) -> K

    +

    function: (T) -> K

    @@ -1995,16 +2022,11 @@

    -

    Returns: Lazy[K]

    +

    Returns: Lazy[K]

    Source code in src\qwlist\qwlist.py -
    318
    -319
    -320
    -321
    -322
    -323
    +            
    323
     324
     325
     326
    @@ -2012,15 +2034,20 @@ 

    328 329 330 -331

    def map(self, mapper: Callable[[T], K]) -> Lazy[K]:
    +331
    +332
    +333
    +334
    +335
    +336
    def map(self, mapper: Callable[[T], K]) -> Lazy[K]:
         """
    -    Returns a Lazy object containing all values from QList with
    +    Returns a `Lazy` object containing all values from `QList` with
         the mapping function applied on them.
     
         Args:
    -        mapper: function: (T) -> K
    +        mapper: `function: (T) -> K`
     
    -    Returns: Lazy[K]
    +    Returns: `Lazy[K]`
         """
         def inner():
             for elem in self:
    @@ -2092,12 +2119,7 @@ 

    Source code in src\qwlist\qwlist.py -
    449
    -450
    -451
    -452
    -453
    -454
    +            
    454
     455
     456
     457
    @@ -2109,7 +2131,12 @@ 

    463 464 465 -466

    def skip(self, n: int) -> Lazy[T]:
    +466
    +467
    +468
    +469
    +470
    +471
    def skip(self, n: int) -> Lazy[T]:
         """
         Skips n first elements of the QList.
     
    @@ -2147,7 +2174,7 @@ 

    -

    Calling this method with slice(3) works similarly to +

    Calling this method with s equal to slice(3) works similarly to list[:3] but is lazy evaluated.

    @@ -2179,7 +2206,7 @@

    -

    Returns: Lazy[T]

    +

    Returns: Lazy[T]

    Source code in src\qwlist\qwlist.py @@ -2200,13 +2227,13 @@

    283 284

    def slice(self, s: slice) -> Lazy[T]:
         """
    -    Calling this method with `slice(3)` works similarly to
    +    Calling this method with `s` equal to `slice(3)` works similarly to
         `list[:3]` but is lazy evaluated.
     
         Args:
             s: slice object
     
    -    Returns: Lazy[T]
    +    Returns: `Lazy[T]`
         """
         assert isinstance(s, slice), f"slice method argument must be a slice object. Got {type(s)}."
     
    @@ -2234,7 +2261,7 @@ 

    -

    Returns a new QList containing all items from the original list in ascending order.

    +

    Returns a new QList containing all items from the original list in ascending order.

    A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order.

    @@ -2258,7 +2285,7 @@

    -

    function (T) -> SupportsLessThan. Defaults to None

    +

    function (T) -> SupportsLessThan. Defaults to None

    @@ -2272,7 +2299,7 @@

    -

    if set to True sorts values in descending order. Defaults to False

    +

    if set to True sorts values in descending order. Defaults to False

    @@ -2281,16 +2308,11 @@

    -

    Returns: QList[T]

    +

    Returns: QList[T]

    Source code in src\qwlist\qwlist.py -
    434
    -435
    -436
    -437
    -438
    -439
    +            
    439
     440
     441
     442
    @@ -2298,18 +2320,23 @@ 

    444 445 446 -447

    def sorted(self, key: Callable[[T], SupportsLessThan] = None, reverse: bool = False) -> "QList[T]":
    +447
    +448
    +449
    +450
    +451
    +452
    def sorted(self, key: Callable[[T], SupportsLessThan] = None, reverse: bool = False) -> "QList[T]":
         """
    -    Returns a new QList containing all items from the original list in ascending order.
    +    Returns a new `QList` containing all items from the original list in ascending order.
     
         A custom key function can be supplied to customize the sort order, and the reverse
         flag can be set to request the result in descending order.
     
         Args:
    -        key: function (T) -> SupportsLessThan. Defaults to None
    -        reverse: if set to True sorts values in descending order. Defaults to False
    +        key: `function (T) -> SupportsLessThan`. Defaults to `None`
    +        reverse: if set to `True` sorts values in descending order. Defaults to `False`
     
    -    Returns: QList[T]
    +    Returns: `QList[T]`
         """
         return QList(sorted(self, key=key, reverse=reverse))
     
    @@ -2374,12 +2401,7 @@

    Source code in src\qwlist\qwlist.py -
    468
    -469
    -470
    -471
    -472
    -473
    +            
    473
     474
     475
     476
    @@ -2392,7 +2414,12 @@ 

    483 484 485 -486

    def take(self, n: int) -> Lazy[T]:
    +486
    +487
    +488
    +489
    +490
    +491
    def take(self, n: int) -> Lazy[T]:
         """
         Takes n first elements of the QList.
     
    @@ -2431,9 +2458,9 @@ 

    -

    Combines this QList with the given Iterable elementwise as tuples. - The returned Lazy objects yields at most the number of elements of - the shorter sequence (self or Iterable).

    +

    Combines this QList with the given Iterable elementwise as tuples. + The returned Lazy objects yields at most the number of elements of + the shorter sequence (self or Iterable).

    @@ -2455,7 +2482,7 @@

    -

    iterable to zip with this QList.

    +

    iterable to zip with this QList.

    @@ -2464,31 +2491,31 @@

    -

    Returns: Lazy[tuple[T, K]]

    +

    Returns: Lazy[tuple[T, K]]

    Source code in src\qwlist\qwlist.py -
    421
    -422
    -423
    -424
    -425
    -426
    +            
    426
     427
     428
     429
     430
     431
    -432
    def zip(self, other: Iterable[K]) -> Lazy[tuple[T, K]]:
    +432
    +433
    +434
    +435
    +436
    +437
    def zip(self, other: Iterable[K]) -> Lazy[tuple[T, K]]:
         """
    -    Combines this QList with the given Iterable elementwise as tuples.
    -     The returned Lazy objects yields at most the number of elements of
    -     the shorter sequence (self or Iterable).
    +    Combines this `QList` with the given `Iterable` elementwise as tuples.
    +     The returned `Lazy` objects yields at most the number of elements of
    +     the shorter sequence (`self` or `Iterable`).
     
         Args:
    -        other: iterable to zip with this QList.
    +        other: iterable to zip with this `QList`.
     
    -    Returns: Lazy[tuple[T, K]]
    +    Returns: `Lazy[tuple[T, K]]`
         """
         return Lazy(zip(self, other))
     
    diff --git a/site/sitemap.xml.gz b/site/sitemap.xml.gz index fb5f1b921cca30bc4b4a3cb1f3e6f5f88e258ebd..f91196d7f8a981346bc216f8fcdc67d2d7ff1a87 100644 GIT binary patch delta 12 Tcmb=gXOr*d;JEc+B3mT@8^Q#c delta 12 Tcmb=gXOr*d;CS|IB3mT@8`cDy diff --git a/src/qwlist/eager.py b/src/qwlist/eager.py index 48fc021..3ca42bb 100644 --- a/src/qwlist/eager.py +++ b/src/qwlist/eager.py @@ -6,6 +6,11 @@ class EagerQList(list): + """ + `EagerQList` is a python list extension that adds several chainable, methods to the standard `list`. + + Found in `qwlist.eager.EagerQList` + """ @overload def __getitem__(self, item: int) -> T: ... @@ -21,76 +26,80 @@ def __getitem__(self, item): def list(self) -> list[T]: """ - Changes EagerQList into list. + Changes `EagerQList` into `list`. - Returns: list[T] + Returns: `list[T]` """ return list(self) def qlist(self) -> "QList[T]": """ - Changes EagerQList into Qlist. + Changes `EagerQList` into `Qlist`. - Returns: QList[T] + Returns: `QList[T]` """ - from qwlist.qwlist import QList + from qwlist import QList return QList(self) def filter(self, pred: Callable[[T], bool]) -> "EagerQList[T]": """ - Returns a EagerQList containing all values from this EagerQList for which + Returns an `EagerQList` containing all values from this `EagerQList` for which the predicate holds true. Args: - pred: function (T) -> bool - Returns: EagerQList[T] + pred: `function (T) -> bool` + + Returns: `EagerQList[T]` + + Examples: + >>> EagerQList([1, 2, 3, 4]).filter(lambda x: x < 3) + [1, 2] """ return EagerQList(elem for elem in self if pred(elem)) def map(self, mapper: Callable[[T], K]) -> "EagerQList[K]": """ - Returns a EagerQList containing all values from this EagerQList with + Returns an `EagerQList` containing all values from this `EagerQList` with the mapping function applied on them. Args: - mapper: function: (T) -> K + mapper: `function: (T) -> K` - Returns: EagerQList[K] + Returns: `EagerQList[K]` """ return EagerQList(mapper(elem) for elem in self) def foreach(self, action: Callable[[T], None]): """ - Applies the given function to each of the EagerQList elements. + Applies the given function to each of the `EagerQList` elements. Args: - action: function (T) -> None + action: `function (T) -> None` - Returns: None + Returns: `None` """ for elem in self: action(elem) def fold(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the EagerQList by processing + Given the combination operator reduces the `EagerQList` by processing its values, building up the final value. **Other names:** fold_left, reduce, accumulate, aggregate Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the given combination operator on each element of the EagerQList, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` - Examples - -------- - >>> s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) - 6 + Examples: + >>> s = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) + 6 """ acc = init for elem in self: @@ -99,22 +108,21 @@ def fold(self, operation: Callable[[K, T], K], init: K) -> K: def fold_right(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the EagerQList by processing + Given the combination operator reduces the `EagerQList` by processing its values, building up the final value. Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the given combination operator on each element of the QList, starting from the last element, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` - Examples - -------- - >>> s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) - 6 + Examples: + >>> s = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) + 6 """ acc = init for elem in self[::-1]: @@ -126,53 +134,52 @@ def len(self): def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> "EagerQList[K]": """ - Applies the mapper function to each element of the EagerQList and flattens the results. + Applies the mapper function to each element of the `EagerQList` and flattens the results. Args: - mapper: function (T) -> Iterable[K] + mapper: `function (T) -> Iterable[K]` - Returns: EagerQList[K] + Returns: `EagerQList[K]` Examples: - -------- - >>> EagerQList([1, 2]).flatmap(lambda x: [x, x]) - [1, 1, 2, 2] + >>> EagerQList([1, 2]).flatmap(lambda x: [x, x]) + [1, 1, 2, 2] """ return EagerQList(x for elem in self for x in mapper(elem)) def zip(self, other: Iterable[K]) -> "EagerQList[tuple[T, K]]": """ - Combines this EagerQList with the given Iterable elementwise as tuples. - The returned EagerQList objects has at most the number of elements of - the shorter sequence (self or Iterable). + Combines this `EagerQList` with the given `Iterable` elementwise as tuples. + The returned `EagerQList` objects has at most the number of elements of + the shorter sequence (`self` or `Iterable`). Args: - other: iterable to zip with this EagerQList. + other: iterable to zip with this `EagerQList`. - Returns: EagerQList[tuple[T, K]] + Returns: `EagerQList[tuple[T, K]]` """ return EagerQList(zip(self, other)) - def sorted(self, key: Callable[[T], SupportsLessThan] = lambda x: x, reverse: bool = False) -> "EagerQList[T]": + def sorted(self, key: Callable[[T], SupportsLessThan] = None, reverse: bool = False) -> "EagerQList[T]": """ - Returns a new EagerQList containing all items from the original list in ascending order. + Returns a new `EagerQList` containing all items from the original list in ascending order. A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order. Args: - key: function (T) -> SupportsLessThan. Defaults to identity function (x: T) -> x - reverse: if set to True sorts values in descending order. Defaults to False + key: `function (T) -> SupportsLessThan`. Defaults to `None` + reverse: if set to `True` sorts values in descending order. Defaults to `False` - Returns: EagerQList[T] + Returns: `EagerQList[T]` """ return EagerQList(sorted(self, key=key, reverse=reverse)) def flatten(self) -> "EagerQList[T]": """ - If self is a EagerQList of Iterable[T] flatten concatenates all iterables into a - single list and returns a new EagerQList[T]. - Returns: EagerQList[T] + If self is a `EagerQList` of `Iterable[T]` flatten concatenates all iterables into a + single list and returns a new `EagerQList[T]`. + Returns: `EagerQList[T]` """ def inner(): for elem in self: diff --git a/src/qwlist/qwlist.py b/src/qwlist/qwlist.py index 8e1ad92..7bbd149 100644 --- a/src/qwlist/qwlist.py +++ b/src/qwlist/qwlist.py @@ -248,7 +248,7 @@ def inner(): class QList(list): """ `QList` is a python list extension that adds several chainable, lazy - evaluated methods to the standard 'list'. + evaluated methods to the standard `list`. Found in `qwlist.QList` """ @@ -268,13 +268,13 @@ def __getitem__(self, item): def slice(self, s: slice) -> Lazy[T]: """ - Calling this method with `slice(3)` works similarly to + Calling this method with `s` equal to `slice(3)` works similarly to `list[:3]` but is lazy evaluated. Args: s: slice object - Returns: Lazy[T] + Returns: `Lazy[T]` """ assert isinstance(s, slice), f"slice method argument must be a slice object. Got {type(s)}." @@ -285,29 +285,34 @@ def inner(): def list(self) -> list[T]: """ - Changes QList into list. + Changes `QList` into `list`. - Returns: list[T] + Returns: `list[T]` """ return list(self) def eager(self) -> "EagerQList[T]": """ - Changes QList into EagerQList. + Changes `QList` into `EagerQList`. - Returns: EagerQList[T] + Returns: `EagerQList[T]` """ from .eager import EagerQList return EagerQList(self) def filter(self, pred: Callable[[T], bool]) -> Lazy[T]: """ - Returns a Lazy object containing all values from the QList for which + Returns a `Lazy` object containing all values from the `QList` for which the predicate holds true. Args: - pred: function (T) -> bool - Returns: Lazy[T] + pred: `function (T) -> bool` + + Returns: `Lazy[T]` + + Examples: + >>> QList([1, 2, 3, 4]).filter(lambda x: x < 3).collect() + [1, 2] """ def inner(): for elem in self: @@ -317,13 +322,13 @@ def inner(): def map(self, mapper: Callable[[T], K]) -> Lazy[K]: """ - Returns a Lazy object containing all values from QList with + Returns a `Lazy` object containing all values from `QList` with the mapping function applied on them. Args: - mapper: function: (T) -> K + mapper: `function: (T) -> K` - Returns: Lazy[K] + Returns: `Lazy[K]` """ def inner(): for elem in self: @@ -332,31 +337,31 @@ def inner(): def foreach(self, action: Callable[[T], None]): """ - Applies the given function to each of the QList elements. + Applies the given function to each of the `QList` elements. Args: - action: function (T) -> None + action: `function (T) -> None` - Returns: None + Returns: `None` """ for elem in self: action(elem) def fold(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the QList by processing + Given the combination operator reduces the `QList` by processing its values, building up the final value. **Other names:** fold_left, reduce, accumulate, aggregate Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the - given combination operator on each element of the QList, + given combination operator on each element of the `QList`, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` Examples: >>> QList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) @@ -369,17 +374,17 @@ def fold(self, operation: Callable[[K, T], K], init: K) -> K: def fold_right(self, operation: Callable[[K, T], K], init: K) -> K: """ - Given the combination operator reduces the QList by processing + Given the combination operator reduces the `QList` by processing its values, building up the final value. Args: - operation: function: (K, T) -> K + operation: `function: (K, T) -> K` Given the initial value `init` applies the - given combination operator on each element of the QList, starting from the + given combination operator on each element of the `QList`, starting from the last element, treating the result as a first argument in the next step. init: initial value for the combination operator. - Returns: K + Returns: `K` Examples: >>> QList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) @@ -392,9 +397,9 @@ def fold_right(self, operation: Callable[[K, T], K], init: K) -> K: def len(self) -> int: """ - Returns the len of the QList + Returns the len of the `QList` - (time complexity: O(1)) + (time complexity: `O(1)`) Returns: int """ @@ -402,12 +407,12 @@ def len(self) -> int: def flatmap(self, mapper: Callable[[T], Iterable[K]]) -> Lazy[K]: """ - Applies the mapper function to each element of the QList and flattens the results. + Applies the mapper function to each element of the `QList` and flattens the results. Args: - mapper: function (T) -> Iterable[K] + mapper: `function (T) -> Iterable[K]` - Returns: Lazy[K] + Returns: `Lazy[K]` Examples: >>> QList([1, 2]).flatmap(lambda x: [x, x]).qlist() @@ -420,29 +425,29 @@ def inner(): def zip(self, other: Iterable[K]) -> Lazy[tuple[T, K]]: """ - Combines this QList with the given Iterable elementwise as tuples. - The returned Lazy objects yields at most the number of elements of - the shorter sequence (self or Iterable). + Combines this `QList` with the given `Iterable` elementwise as tuples. + The returned `Lazy` objects yields at most the number of elements of + the shorter sequence (`self` or `Iterable`). Args: - other: iterable to zip with this QList. + other: iterable to zip with this `QList`. - Returns: Lazy[tuple[T, K]] + Returns: `Lazy[tuple[T, K]]` """ return Lazy(zip(self, other)) def sorted(self, key: Callable[[T], SupportsLessThan] = None, reverse: bool = False) -> "QList[T]": """ - Returns a new QList containing all items from the original list in ascending order. + Returns a new `QList` containing all items from the original list in ascending order. A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order. Args: - key: function (T) -> SupportsLessThan. Defaults to None - reverse: if set to True sorts values in descending order. Defaults to False + key: `function (T) -> SupportsLessThan`. Defaults to `None` + reverse: if set to `True` sorts values in descending order. Defaults to `False` - Returns: QList[T] + Returns: `QList[T]` """ return QList(sorted(self, key=key, reverse=reverse)) diff --git a/tests/eager.py b/tests/eager.py index e69de29..905adcf 100644 --- a/tests/eager.py +++ b/tests/eager.py @@ -0,0 +1,203 @@ +import sys; sys.path.append('../src') +from src.qwlist.qwlist import QList +from src.qwlist.eager import EagerQList +import pytest + + +def test_qlist_from_iterable_constructor(): + expected = EagerQList([0, 1, 2]) + res = EagerQList(range(3)) + for e, r in zip(expected, res): + assert e == r + + +def test_len(): + assert 3 == EagerQList([0, 1, 2]).len() + + +def test_conversion_to_list(): + expected = [1, 2, 3] + res = EagerQList([1, 2, 3]).list() + assert isinstance(res, list) + assert expected == res + + +def test_conversion_to_qlist(): + expected = QList([1, 2, 3]) + res = EagerQList([1, 2, 3]).qlist() + assert isinstance(res, QList) + assert expected == res + + +def test_empty_constructor(): + expect = [] + res = EagerQList().list() + assert expect == res + + +def test_eager_qlist_from_generator(): + def gen(): + yield 1 + yield 2 + yield 3 + expected = EagerQList([1, 2, 3]) + res = EagerQList(gen()) + assert expected == res + + +def test_getitem_index(): + qlist = EagerQList([1, 2, 3]) + assert 1 == qlist[0] + assert 3 == qlist[-1] + pytest.raises(IndexError, lambda: qlist[3]) + pytest.raises(IndexError, lambda: qlist[-4]) + + +def test_getitem_slice(): + qlist = EagerQList(range(10)) + assert isinstance(qlist[:], EagerQList) + assert qlist == qlist[:] + assert [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] == qlist[::-1].list() + assert EagerQList([0, 1, 2]) == qlist[:3] + assert EagerQList([0, 2, 4]) == qlist[:6:2] + + +def test_map(): + expected = EagerQList(['0', '1', '2']) + res = EagerQList(range(3)).map(str) + assert expected == res + + +def test_filter(): + expected = EagerQList([0, 2, 4]) + res = EagerQList(range(5)).filter(lambda x: x % 2 == 0) + assert expected == res + + +def test_flatmap(): + expected = EagerQList([0, 0, 1, 1]) + res = EagerQList(range(2)).flatmap(lambda x: [x, x]) + assert expected == res, 'standard flatmap failed' + + expected = EagerQList() + res = EagerQList(range(10)).flatmap(lambda x: []) + assert expected == res, 'flatmap to empty list failed' + + +def test_foreach(): + counter = 0 + + def counter_up(x): + nonlocal counter + counter += 1 + + EagerQList().foreach(counter_up) + assert 0 == counter + + EagerQList(range(10)).foreach(counter_up) + assert 10 == counter + + elem_sum = 0 + + def side_effect_sum(x): + nonlocal elem_sum + elem_sum += x + + EagerQList(range(4)).foreach(side_effect_sum) + assert 6 == elem_sum + + +def test_fold(): + expected = 6 + res = EagerQList([1, 2, 3]).fold(lambda acc, x: acc + x, 0) + assert expected == res + + expected = '123' + res = EagerQList(['1', '2', '3']).fold(lambda acc, x: acc + x, '') + assert expected == res + + expected = '321' + res = EagerQList(['1', '2', '3']).fold(lambda acc, x: x + acc, '') + assert expected == res + + res = EagerQList(range(10)).fold(lambda acc, x: 0, 0) + assert 0 == res + + +def test_fold_right(): + expected = 6 + res = EagerQList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0) + assert expected == res + + expected = '123' + res = EagerQList(['1', '2', '3']).fold_right(lambda acc, x: x + acc, '') + assert expected == res + + expected = '321' + res = EagerQList(['1', '2', '3']).fold_right(lambda acc, x: acc + x, '') + assert expected == res + + res = EagerQList(range(10)).fold_right(lambda acc, x: 0, 0) + assert 0 == res + + +def test_zip(): + expected = EagerQList([(1, 0), (2, 1), (3, 2)]) + res = EagerQList([1, 2, 3]).zip([0, 1, 2]) + assert expected == res + + expected = EagerQList([(1, 0), (2, 1), (3, 2)]) + res = EagerQList([1, 2, 3]).zip(range(100)) + assert expected == res + + expected = EagerQList() + res = EagerQList(range(10)).zip(QList()) + assert expected == res + + +def test_sorted(): + expected = EagerQList(range(5)) + res = EagerQList([0, 2, 1, 3, 4]).sorted() + assert expected == res + res = EagerQList([0, 2, 1, 3, 4]).sorted(reverse=True) + assert expected[::-1] == res + + expected = EagerQList([(4, 'a'), (3, 'b'), (7, 'c')]) + res = EagerQList([(3, 'b'), (4, 'a'), (7, 'c')]).sorted(key=lambda x: x[1]) + assert expected == res + + +def test_method_chaining(): + res = ( + EagerQList(range(100)) + .filter(lambda x: x % 3 == 0)[:10] + .map(str)[6:] + .zip(range(4)) + .flatmap(lambda pair: ((pair[0], n) for n in range(pair[1]))) + .fold(lambda acc, x: acc + x[1], 0) + ) + assert 4 == res + + +def test_methods_are_eager(): + qlist = EagerQList([1, 2, 3]) + assert isinstance(qlist.map(str), EagerQList) + assert isinstance(qlist.filter(bool), EagerQList) + assert isinstance(qlist.flatmap(lambda x: [x, x]), EagerQList) + assert isinstance(qlist.zip(range(3)), EagerQList) + assert isinstance(EagerQList([[1, 1]]).flatten(), EagerQList) + + +def test_flatten(): + expected = EagerQList([1, 2, 3, 1, 2, 3]) + res = EagerQList([[1, 2, 3], [1, 2, 3]]).flatten() + assert expected == res + + expected = EagerQList() + res = EagerQList([[], [], []]).flatten() + assert expected == res + + expected = EagerQList([[1, 2], [1, 2], [1, 2]]) + res = EagerQList([[[1, 2], [1, 2], [1, 2]]]).flatten() + assert expected == res + diff --git a/tests/test_qwlist.py b/tests/test_qwlist.py index 15cdcea..80344e7 100644 --- a/tests/test_qwlist.py +++ b/tests/test_qwlist.py @@ -62,12 +62,6 @@ def test_getitem_slice(): assert QList([0, 2, 4]) == qlist[:6:2] -def test_lazy_operations(): - expected = QList(range(3)) - res = expected.map(lambda x: x).collect() - assert expected == res - - def test_map(): expected = QList(['0', '1', '2']) res = QList(range(3)).map(str).collect() @@ -237,6 +231,7 @@ def test_methods_are_lazy(): assert isinstance(qlist.slice(slice(3)), Lazy) assert isinstance(qlist.take(3), Lazy) assert isinstance(qlist.skip(3), Lazy) + assert isinstance(QList([[1, 1]]).flatten(), Lazy) def test_flatten():