Revision | a56dc73f7d466b9fe5a3c76afb488b51185ccfe5 (tree) |
---|---|
Time | 2022-06-23 23:28:15 |
Author | Antoon Pardon <aej@pard...> |
Commiter | Antoon Pardon |
Discard pipe iterator added
@@ -26,6 +26,7 @@ | ||
26 | 26 | |
27 | 27 | cd $PROJECTDIRECTORY |
28 | 28 | |
29 | - | |
29 | +echo checking TESTS | |
30 | 30 | pushd tests > /dev/null; make all; popd > /dev/null |
31 | +echo checking SOURCE | |
31 | 32 | pushd source > /dev/null; make all; popd > /dev/null |
@@ -19,7 +19,7 @@ | ||
19 | 19 | |
20 | 20 | .lint: $(PYTHON) |
21 | 21 | echo $(PYCS) |
22 | - pylint --disable C0114,C0103,C0116,E0213 $? | |
22 | + pylint --disable=trailing-whitespace $? | |
23 | 23 | #doall pylint $? |
24 | 24 | touch .lint |
25 | 25 |
@@ -30,7 +30,7 @@ | ||
30 | 30 | |
31 | 31 | from typing import Callable, Iterator, Iterable, cast, Any |
32 | 32 | from functools import partial |
33 | -from itertools import chain | |
33 | +from itertools import chain, filterfalse | |
34 | 34 | |
35 | 35 | # |
36 | 36 | # Pipe line iterators inspired by Steven D'Aprano |
@@ -64,7 +64,7 @@ | ||
64 | 64 | This class produces a pipe iterator that will turn an iterator into a new |
65 | 65 | iterator where the new items are the result of applying the function. |
66 | 66 | |
67 | - double = partial(operator.__mul__, 2) | |
67 | + double = partial(operator.__mul__, 2) | |
68 | 68 | [3, 5, 8] | Map(double) --> 6, 10, 16 |
69 | 69 | """ |
70 | 70 | # pylint: disable=too-few-public-methods |
@@ -76,7 +76,7 @@ | ||
76 | 76 | This class produces a pipe iterator that will turn an iterable of iterables |
77 | 77 | into a new iterables of iterables where the new items are the result of applying the function. |
78 | 78 | |
79 | - double = partial(operator.__mul__, 2) | |
79 | + double = partial(operator.__mul__, 2) | |
80 | 80 | [[3, 5, 8], [7, 4], [2]] | SubMap(double) --> [6, 10, 16], [14, 8], [4] |
81 | 81 | """ |
82 | 82 | # pylint: disable=too-few-public-methods |
@@ -105,7 +105,20 @@ | ||
105 | 105 | """ |
106 | 106 | This class produces a pipe iterator that only lets items through that are |
107 | 107 | selected through the condition. |
108 | + | |
109 | + [21, 13, 8, 5, 3, 2] >> Select(is_odd) --> 21 13 5 3 | |
108 | 110 | """ |
109 | 111 | # pylint: disable=too-few-public-methods |
110 | 112 | def __init__(self, condition: Callable[[Iterator[Any]], Any] ): |
111 | 113 | super().__init__(partial(filter, condition)) |
114 | + | |
115 | +class Discard(PipeIterator): | |
116 | + """ | |
117 | + This class produces a pipe iterator that removes items that are | |
118 | + filtered out through the condition. | |
119 | + | |
120 | + [21, 13, 8, 5, 3, 2] >> Discard(is_odd) --> 8 2 | |
121 | + """ | |
122 | + # pylint: disable=too-few-public-methods | |
123 | + def __init__(self, condition: Callable[[Iterator[Any]], Any] ): | |
124 | + super().__init__(partial(filterfalse, condition)) |
@@ -1,3 +1,3 @@ | ||
1 | -version = '0.01.00k' | |
2 | -modified = '2022-06-23 @ 15:23:41' | |
1 | +version = '0.01.01j' | |
2 | +modified = '2022-06-23 @ 16:23:51' | |
3 | 3 | installed = '*********************' |
@@ -1,3 +1,11 @@ | ||
1 | +""" | |
2 | +This modules collects the release information from | |
3 | +the release config file. The main puropse is to | |
4 | +easily allow the users the consult which release | |
5 | +they are using with the following command: | |
6 | + | |
7 | +python3 -m AGPlib.release | |
8 | +""" | |
1 | 9 | |
2 | 10 | import os.path |
3 | 11 |
@@ -25,7 +25,7 @@ | ||
25 | 25 | touch .mypy |
26 | 26 | |
27 | 27 | .lint: $(PYTHON) $(TESTS) #$(PTESTS) |
28 | - pylint --disable C0114,C0103,C0116,E0213 $? | |
28 | + pylint $? | |
29 | 29 | #doall pylint $? |
30 | 30 | touch .lint |
31 | 31 |
@@ -1,3 +1,5 @@ | ||
1 | + | |
2 | +# pylint: disable=missing-function-docstring,invalid-name,missing-module-docstring | |
1 | 3 | |
2 | 4 | from unittest import TestCase, main as unitmain |
3 | 5 | from random import shuffle |
@@ -5,7 +7,7 @@ | ||
5 | 7 | from typing import List |
6 | 8 | |
7 | 9 | # pylint: disable=unused-import |
8 | -from AGPlib.iterators import PipeIterator, Apply, Map, concat, SubMap, Select | |
10 | +from AGPlib.iterators import PipeIterator, Apply, Map, concat, SubMap, Select, Discard | |
9 | 11 | # pylint: enable=unused-import |
10 | 12 | |
11 | 13 | def shuffled_range_list(*args) -> List[int]: |
@@ -40,6 +42,8 @@ | ||
40 | 42 | for sub_iterable in iterable: |
41 | 43 | yield from sub_iterable |
42 | 44 | |
45 | +# pylint: disable=no-self-argument | |
46 | + | |
43 | 47 | class PipeCase(TestCase): |
44 | 48 | """ |
45 | 49 | class for testing the PipeIterators |
@@ -96,4 +100,15 @@ | ||
96 | 100 | s.assertEqual(result0, result1) |
97 | 101 | s.assertEqual(result0, result2) |
98 | 102 | |
103 | + def test_discard(s): | |
104 | + # pylint: disable=redefined-outer-name | |
105 | + List = Apply(list) | |
106 | + source = shuffled_range_list(100) | |
107 | + for condition in [is_odd, is_larger_than_50]: | |
108 | + result0 = [nr for nr in source if not condition(nr)] | |
109 | + result1 = source | Discard(condition) | List | |
110 | + result2 = source >> Discard(condition) >> List | |
111 | + s.assertEqual(result0, result1) | |
112 | + s.assertEqual(result0, result2) | |
113 | + | |
99 | 114 | unitmain() |