2021-07-27 09:26:30 +02:00
|
|
|
from typing import Optional, Callable, Union
|
2021-07-26 15:21:57 +02:00
|
|
|
|
2021-07-26 15:52:27 +02:00
|
|
|
from cpl_query._extension.ordered_iterable import OrderedIterable
|
|
|
|
from cpl_query.extension.ordered_iterable_abc import OrderedIterableABC
|
2021-07-27 09:15:19 +02:00
|
|
|
from .._query.all_query import all_query
|
2021-07-26 15:21:57 +02:00
|
|
|
from .._query.any_query import any_query
|
2021-07-27 09:26:30 +02:00
|
|
|
from .._query.avg_query import avg_query
|
2021-07-27 10:55:23 +02:00
|
|
|
from .._query.contains_query import contains_query
|
2021-07-27 11:01:43 +02:00
|
|
|
from .._query.count_query import count_query
|
2021-07-27 11:20:35 +02:00
|
|
|
from .._query.distinct_query import distinct_query
|
2021-07-26 15:21:57 +02:00
|
|
|
from .._query.first_query import first_or_default_query, first_query
|
|
|
|
from .._query.for_each_query import for_each_query
|
|
|
|
from .._query.order_by import order_by_query, order_by_descending_query
|
|
|
|
from .._query.single_query import single_query, single_or_default_query
|
|
|
|
from .._query.where_query import where_query
|
|
|
|
from cpl_query.extension.iterable_abc import IterableABC
|
|
|
|
|
|
|
|
|
|
|
|
class Iterable(IterableABC):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
IterableABC.__init__(self)
|
|
|
|
|
2021-07-26 15:32:28 +02:00
|
|
|
def any(self, func: Callable) -> bool:
|
2021-07-26 15:21:57 +02:00
|
|
|
return any_query(self, func)
|
|
|
|
|
2021-07-27 09:15:19 +02:00
|
|
|
def all(self, func: Callable) -> bool:
|
|
|
|
return all_query(self, func)
|
|
|
|
|
2021-07-27 09:26:30 +02:00
|
|
|
def average(self, t: type, func: Callable) -> Union[int, float, complex]:
|
|
|
|
return avg_query(self, t, func)
|
|
|
|
|
2021-07-27 10:55:23 +02:00
|
|
|
def contains(self, value: object) -> bool:
|
|
|
|
return contains_query(self, value)
|
|
|
|
|
2021-07-27 11:01:43 +02:00
|
|
|
def count(self, func: Callable = None) -> int:
|
|
|
|
return count_query(self, func)
|
|
|
|
|
2021-07-27 11:20:35 +02:00
|
|
|
def distinct(self, func: Callable) -> IterableABC:
|
|
|
|
res = distinct_query(self, func)
|
|
|
|
res.__class__ = Iterable
|
|
|
|
return res
|
|
|
|
|
2021-07-26 15:21:57 +02:00
|
|
|
def first(self) -> any:
|
|
|
|
return first_query(self)
|
|
|
|
|
|
|
|
def first_or_default(self) -> Optional[any]:
|
|
|
|
return first_or_default_query(self)
|
|
|
|
|
|
|
|
def for_each(self, func: Callable):
|
|
|
|
for_each_query(self, func)
|
|
|
|
|
|
|
|
def order_by(self, func: Callable) -> OrderedIterableABC:
|
|
|
|
res = order_by_query(self, func)
|
|
|
|
res.__class__ = OrderedIterable
|
|
|
|
return res
|
|
|
|
|
|
|
|
def order_by_descending(self, func: Callable) -> OrderedIterableABC:
|
|
|
|
res = order_by_descending_query(self, func)
|
|
|
|
res.__class__ = OrderedIterable
|
|
|
|
return res
|
|
|
|
|
|
|
|
def single(self) -> any:
|
|
|
|
return single_query(self)
|
|
|
|
|
|
|
|
def single_or_default(self) -> Optional[any]:
|
|
|
|
return single_or_default_query(self)
|
|
|
|
|
2021-07-26 15:32:28 +02:00
|
|
|
def where(self, func: Callable) -> IterableABC:
|
2021-07-26 15:21:57 +02:00
|
|
|
res = where_query(self, func)
|
|
|
|
res.__class__ = Iterable
|
|
|
|
return res
|
|
|
|
|
|
|
|
def to_list(self) -> list:
|
|
|
|
return list(self)
|