sh_cpl/src/cpl_query/extension/ordered_iterable.py

23 lines
834 B
Python
Raw Normal View History

2021-07-26 15:21:57 +02:00
from collections import Callable
2021-11-02 17:30:10 +01:00
from iterable import Iterable
2021-07-26 15:21:57 +02:00
from .._query.order_by import then_by_query, then_by_descending_query
2021-11-02 17:30:10 +01:00
from ordered_iterable_abc import OrderedIterableABC
2021-07-26 15:21:57 +02:00
2021-07-27 13:57:42 +02:00
class OrderedIterable(Iterable, OrderedIterableABC):
2021-11-02 17:30:10 +01:00
r"""Implementation of :class: `cpl_query.extension.Iterable` `cpl_query.extension.OrderedIterableABC`
"""
2021-07-26 15:21:57 +02:00
def __init__(self):
2021-07-27 13:57:42 +02:00
Iterable.__init__(self)
2021-07-26 15:21:57 +02:00
OrderedIterableABC.__init__(self)
def then_by(self, _func: Callable) -> OrderedIterableABC:
self._funcs.append(_func)
return then_by_query(self, lambda *args: [f(*args) for f in self._funcs])
def then_by_descending(self, _func: Callable) -> OrderedIterableABC:
self._funcs.append(_func)
return then_by_descending_query(self, lambda *args: [f(*args) for f in self._funcs])