2021.10.3 #35

Merged
edraft merged 31 commits from 2021.10.3 into 2021.10 2021-08-02 14:36:46 +02:00
4 changed files with 32 additions and 3 deletions
Showing only changes of commit 62c8b9c68d - Show all commits

View File

@ -13,6 +13,7 @@ from .._query.first_last import first_or_default_query, first_query, last_or_def
from .._query.for_each import for_each_query
from .._query.max_min import max_query, min_query
from .._query.order_by import order_by_query, order_by_descending_query
from .._query.reverse import reverse_query
from .._query.single import single_query, single_or_default_query
from .._query.where import where_query
from cpl_query.extension.iterable_abc import IterableABC
@ -80,6 +81,9 @@ class Iterable(IterableABC):
res.__class__ = OrderedIterable
return res
def reverse(self) -> IterableABC:
return reverse_query(self)
def single(self) -> any:
return single_query(self)
@ -90,6 +94,3 @@ class Iterable(IterableABC):
res = where_query(self, func)
res.__class__ = Iterable
return res
def to_list(self) -> list:
return list(self)

View File

@ -0,0 +1,15 @@
from cpl_query.exceptions import ArgumentNoneException, ExceptionArgument
from cpl_query.extension.iterable_abc import IterableABC
def reverse_query(_list: IterableABC) -> IterableABC:
if _list is None:
raise ArgumentNoneException(ExceptionArgument.list)
result = IterableABC()
_copied_list = _list.to_list()
_copied_list.reverse()
for element in _copied_list:
result.append(element)
return result

View File

@ -80,9 +80,15 @@ class IterableABC(ABC, list):
@abstractmethod
def order_by_descending(self, func: Callable) -> 'IterableABC': pass
@abstractmethod
def reverse(self) -> 'IterableABC': pass
@abstractmethod
def single(self) -> any: pass
def to_list(self) -> list:
return list(self)
@abstractmethod
def single_or_default(self) -> Optional[any]: pass

View File

@ -228,6 +228,13 @@ class QueryTest(unittest.TestCase):
self.assertEqual(res, s_res)
def test_reverse(self):
res = self._tests.reverse()
l_res = self._tests.to_list()
l_res.reverse()
self.assertEqual(l_res, res)
def test_single(self):
res = self._tests.where(lambda u: u.address.nr == self._t_user.address.nr)
s_res = self._tests.where(lambda u: u.address.nr == self._t_user.address.nr).single()