Commit MetaInfo

Revisiona56dc73f7d466b9fe5a3c76afb488b51185ccfe5 (tree)
Time2022-06-23 23:28:15
AuthorAntoon Pardon <aej@pard...>
CommiterAntoon Pardon

Log Message

Discard pipe iterator added

Change Summary

Incremental Difference

diff -r d3beb8e84c19 -r a56dc73f7d46 prepare
--- a/prepare Thu Jun 23 15:24:31 2022 +0200
+++ b/prepare Thu Jun 23 16:28:15 2022 +0200
@@ -26,6 +26,7 @@
2626
2727 cd $PROJECTDIRECTORY
2828
29-
29+echo checking TESTS
3030 pushd tests > /dev/null; make all; popd > /dev/null
31+echo checking SOURCE
3132 pushd source > /dev/null; make all; popd > /dev/null
diff -r d3beb8e84c19 -r a56dc73f7d46 source/Makefile
--- a/source/Makefile Thu Jun 23 15:24:31 2022 +0200
+++ b/source/Makefile Thu Jun 23 16:28:15 2022 +0200
@@ -19,7 +19,7 @@
1919
2020 .lint: $(PYTHON)
2121 echo $(PYCS)
22- pylint --disable C0114,C0103,C0116,E0213 $?
22+ pylint --disable=trailing-whitespace $?
2323 #doall pylint $?
2424 touch .lint
2525
diff -r d3beb8e84c19 -r a56dc73f7d46 source/iterators.py
--- a/source/iterators.py Thu Jun 23 15:24:31 2022 +0200
+++ b/source/iterators.py Thu Jun 23 16:28:15 2022 +0200
@@ -30,7 +30,7 @@
3030
3131 from typing import Callable, Iterator, Iterable, cast, Any
3232 from functools import partial
33-from itertools import chain
33+from itertools import chain, filterfalse
3434
3535 #
3636 # Pipe line iterators inspired by Steven D'Aprano
@@ -64,7 +64,7 @@
6464 This class produces a pipe iterator that will turn an iterator into a new
6565 iterator where the new items are the result of applying the function.
6666
67- double = partial(operator.__mul__, 2)
67+ double = partial(operator.__mul__, 2)
6868 [3, 5, 8] | Map(double) --> 6, 10, 16
6969 """
7070 # pylint: disable=too-few-public-methods
@@ -76,7 +76,7 @@
7676 This class produces a pipe iterator that will turn an iterable of iterables
7777 into a new iterables of iterables where the new items are the result of applying the function.
7878
79- double = partial(operator.__mul__, 2)
79+ double = partial(operator.__mul__, 2)
8080 [[3, 5, 8], [7, 4], [2]] | SubMap(double) --> [6, 10, 16], [14, 8], [4]
8181 """
8282 # pylint: disable=too-few-public-methods
@@ -105,7 +105,20 @@
105105 """
106106 This class produces a pipe iterator that only lets items through that are
107107 selected through the condition.
108+
109+ [21, 13, 8, 5, 3, 2] >> Select(is_odd) --> 21 13 5 3
108110 """
109111 # pylint: disable=too-few-public-methods
110112 def __init__(self, condition: Callable[[Iterator[Any]], Any] ):
111113 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))
diff -r d3beb8e84c19 -r a56dc73f7d46 source/release.cfg
--- a/source/release.cfg Thu Jun 23 15:24:31 2022 +0200
+++ b/source/release.cfg Thu Jun 23 16:28:15 2022 +0200
@@ -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'
33 installed = '*********************'
diff -r d3beb8e84c19 -r a56dc73f7d46 source/release.py
--- a/source/release.py Thu Jun 23 15:24:31 2022 +0200
+++ b/source/release.py Thu Jun 23 16:28:15 2022 +0200
@@ -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+"""
19
210 import os.path
311
diff -r d3beb8e84c19 -r a56dc73f7d46 tests/Makefile
--- a/tests/Makefile Thu Jun 23 15:24:31 2022 +0200
+++ b/tests/Makefile Thu Jun 23 16:28:15 2022 +0200
@@ -25,7 +25,7 @@
2525 touch .mypy
2626
2727 .lint: $(PYTHON) $(TESTS) #$(PTESTS)
28- pylint --disable C0114,C0103,C0116,E0213 $?
28+ pylint $?
2929 #doall pylint $?
3030 touch .lint
3131
diff -r d3beb8e84c19 -r a56dc73f7d46 tests/iterators.py
--- a/tests/iterators.py Thu Jun 23 15:24:31 2022 +0200
+++ b/tests/iterators.py Thu Jun 23 16:28:15 2022 +0200
@@ -1,3 +1,5 @@
1+
2+# pylint: disable=missing-function-docstring,invalid-name,missing-module-docstring
13
24 from unittest import TestCase, main as unitmain
35 from random import shuffle
@@ -5,7 +7,7 @@
57 from typing import List
68
79 # 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
911 # pylint: enable=unused-import
1012
1113 def shuffled_range_list(*args) -> List[int]:
@@ -40,6 +42,8 @@
4042 for sub_iterable in iterable:
4143 yield from sub_iterable
4244
45+# pylint: disable=no-self-argument
46+
4347 class PipeCase(TestCase):
4448 """
4549 class for testing the PipeIterators
@@ -96,4 +100,15 @@
96100 s.assertEqual(result0, result1)
97101 s.assertEqual(result0, result2)
98102
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+
99114 unitmain()
Show on old repository browser