Skip to content

Commit

Permalink
pypi version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
WitoldFracek committed Nov 13, 2023
1 parent 4ed51d8 commit 94b7988
Show file tree
Hide file tree
Showing 8 changed files with 823 additions and 642 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "qwlist"
version = "0.1.7"
version = "0.1.8"
authors = [
{ name="Witold Frącek" },
]
Expand Down
646 changes: 295 additions & 351 deletions site/eager/index.html

Large diffs are not rendered by default.

425 changes: 226 additions & 199 deletions site/qlist/index.html

Large diffs are not rendered by default.

Binary file modified site/sitemap.xml.gz
Binary file not shown.
101 changes: 54 additions & 47 deletions src/qwlist/eager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
...
Expand All @@ -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:
Expand All @@ -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]:
Expand All @@ -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:
Expand Down
Loading

0 comments on commit 94b7988

Please sign in to comment.