#161 #162
@ -1,4 +1,5 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Self
|
||||
|
||||
from cpl_query.base.ordered_queryable_abc import OrderedQueryableABC
|
||||
from cpl_query.exceptions import ArgumentNoneException, ExceptionArgument
|
||||
@ -6,12 +7,12 @@ from cpl_query.iterable.iterable import Iterable
|
||||
|
||||
|
||||
class OrderedQueryable(OrderedQueryableABC):
|
||||
r"""Implementation of :class: `cpl_query.extension.Iterable` `cpl_query.extension.OrderedIterableABC`"""
|
||||
r"""Implementation of :class: `cpl_query.base.ordered_queryable_abc.OrderedQueryableABC`"""
|
||||
|
||||
def __init__(self, _t: type, _values: Iterable = None, _func: Callable = None):
|
||||
OrderedQueryableABC.__init__(self, _t, _values, _func)
|
||||
|
||||
def then_by(self: OrderedQueryableABC, _func: Callable) -> OrderedQueryableABC:
|
||||
def then_by(self, _func: Callable) -> Self:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
@ -22,7 +23,7 @@ class OrderedQueryable(OrderedQueryableABC):
|
||||
|
||||
return OrderedQueryable(self.type, sorted(self, key=lambda *args: [f(*args) for f in self._funcs]), _func)
|
||||
|
||||
def then_by_descending(self: OrderedQueryableABC, _func: Callable) -> OrderedQueryableABC:
|
||||
def then_by_descending(self, _func: Callable) -> Self:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, Callable, Union, Iterable, Self
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from cpl_query._helper import is_number
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from cpl_query.base.ordered_queryable_abc import OrderedQueryableABC
|
||||
from cpl_query.base.sequence import Sequence
|
||||
from cpl_query.exceptions import (
|
||||
InvalidTypeException,
|
||||
@ -315,7 +321,7 @@ class QueryableABC(Sequence):
|
||||
|
||||
return _func(min(self, key=_func))
|
||||
|
||||
def order_by(self, _func: Callable = None) -> "OrderedQueryableABC":
|
||||
def order_by(self, _func: Callable = None) -> OrderedQueryableABC:
|
||||
r"""Sorts elements by function in ascending order
|
||||
|
||||
Parameter
|
||||
|
@ -251,6 +251,8 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(res, s_res)
|
||||
|
||||
def test_then_by_descending(self):
|
||||
x = List(int, List.range(1, 10)).order_by(lambda x: x).th
|
||||
|
||||
res = (
|
||||
self._tests.order_by_descending(lambda user: user.address.street)
|
||||
.then_by_descending(lambda user: user.address.nr)
|
||||
|
Loading…
Reference in New Issue
Block a user