2021.10 #41

Merged
edraft merged 53 commits from 2021.10 into master 2021-10-04 09:32:42 +02:00
4 changed files with 16 additions and 0 deletions
Showing only changes of commit f8bd86692e - Show all commits

View File

@ -5,6 +5,7 @@ from cpl_query.extension.ordered_iterable_abc import OrderedIterableABC
from .._query.all_query import all_query
from .._query.any_query import any_query
from .._query.avg_query import avg_query
from .._query.contains_query import contains_query
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
@ -27,6 +28,9 @@ class Iterable(IterableABC):
def average(self, t: type, func: Callable) -> Union[int, float, complex]:
return avg_query(self, t, func)
def contains(self, value: object) -> bool:
return contains_query(self, value)
def first(self) -> any:
return first_query(self)

View File

@ -0,0 +1,5 @@
from cpl_query.extension.iterable_abc import IterableABC
def contains_query(_list: IterableABC, value: object) -> bool:
return value in _list

View File

@ -17,6 +17,9 @@ class IterableABC(ABC, list):
@abstractmethod
def average(self, t: type, func: Callable) -> Union[int, float, complex]: pass
@abstractmethod
def contains(self, value: object) -> bool: pass
@abstractmethod
def first(self) -> any: pass

View File

@ -79,6 +79,10 @@ class QueryTest(unittest.TestCase):
self.assertRaises(InvalidTypeException, invalid)
self.assertRaises(WrongTypeException, wrong)
def test_contains(self):
self.assertTrue(self._tests.contains(self._t_user))
self.assertFalse(self._tests.contains(User("Test", None)))
def test_first(self):
results = []
for user in self._tests: