tinystream 0.1.17__tar.gz → 0.1.18__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tinystream-0.1.17/tinystream.egg-info → tinystream-0.1.18}/PKG-INFO +3 -2
- {tinystream-0.1.17 → tinystream-0.1.18}/README.md +2 -1
- {tinystream-0.1.17 → tinystream-0.1.18}/tests/test_opt.py +12 -3
- {tinystream-0.1.17 → tinystream-0.1.18}/tests/test_streams.py +2 -3
- {tinystream-0.1.17 → tinystream-0.1.18/tinystream.egg-info}/PKG-INFO +3 -2
- {tinystream-0.1.17 → tinystream-0.1.18}/tinystream.py +10 -19
- {tinystream-0.1.17 → tinystream-0.1.18}/LICENSE +0 -0
- {tinystream-0.1.17 → tinystream-0.1.18}/setup.cfg +0 -0
- {tinystream-0.1.17 → tinystream-0.1.18}/setup.py +0 -0
- {tinystream-0.1.17 → tinystream-0.1.18}/tinystream.egg-info/SOURCES.txt +0 -0
- {tinystream-0.1.17 → tinystream-0.1.18}/tinystream.egg-info/dependency_links.txt +0 -0
- {tinystream-0.1.17 → tinystream-0.1.18}/tinystream.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tinystream
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.18
|
|
4
4
|
Summary: Yet another python streams library
|
|
5
5
|
Home-page: https://github.com/mreiche/python-streams
|
|
6
6
|
Author: Mike Reiche
|
|
@@ -13,8 +13,9 @@ Dynamic: home-page
|
|
|
13
13
|
Dynamic: license-file
|
|
14
14
|
Dynamic: summary
|
|
15
15
|
|
|
16
|
-

|
|
16
|
+
[](https://github.com/mreiche/python-streams/actions/workflows/tests.yml)
|
|
17
17
|
[](https://app.codecov.io/github/mreiche/python-streams)
|
|
18
|
+
[](https://badge.fury.io/py/tinystream)
|
|
18
19
|
|
|
19
20
|
# tinystream / python-streams
|
|
20
21
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-

|
|
1
|
+
[](https://github.com/mreiche/python-streams/actions/workflows/tests.yml)
|
|
2
2
|
[](https://app.codecov.io/github/mreiche/python-streams)
|
|
3
|
+
[](https://badge.fury.io/py/tinystream)
|
|
3
4
|
|
|
4
5
|
# tinystream / python-streams
|
|
5
6
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
1
3
|
import pytest
|
|
2
4
|
|
|
3
5
|
from test_streams import Node
|
|
@@ -5,7 +7,6 @@ from tinystream import Opt
|
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
def test_opt_absent():
|
|
8
|
-
assert Opt(None).empty
|
|
9
10
|
assert Opt(None).absent
|
|
10
11
|
|
|
11
12
|
|
|
@@ -60,7 +61,6 @@ def test_opt_empty_if_empty_callable():
|
|
|
60
61
|
|
|
61
62
|
def test_opt_empty_if_empty_value():
|
|
62
63
|
assert Opt(None).if_absent("Empty").get() == "Empty"
|
|
63
|
-
assert Opt(None).if_empty("Empty").get() == "Empty"
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
def test_opt_value_map():
|
|
@@ -106,7 +106,7 @@ def test_none_opt_len():
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
def test_none_opt_map_key():
|
|
109
|
-
assert Opt(None).
|
|
109
|
+
assert Opt(None).kmap("inexistent").absent
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
def test_filter_type():
|
|
@@ -129,6 +129,7 @@ def test_filter_key_value():
|
|
|
129
129
|
opt = Opt({"name": "Hallo"})
|
|
130
130
|
assert opt.filter_key_value("name", "Hallo").present
|
|
131
131
|
assert opt.filter_key_value("name", "Katze").absent
|
|
132
|
+
assert opt.map_key("inexistent").filter_key_value("name", "value").absent
|
|
132
133
|
|
|
133
134
|
|
|
134
135
|
def test_map_key_value():
|
|
@@ -170,3 +171,11 @@ def test_stream():
|
|
|
170
171
|
def test_dict_map_kwargs():
|
|
171
172
|
opt = Opt({"name": "First"})
|
|
172
173
|
assert opt.map_kwargs(Node).get().name == "First"
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_map_enum():
|
|
177
|
+
class AnalysisAnalysisState(str, Enum):
|
|
178
|
+
NOT_SET = "NOT_SET"
|
|
179
|
+
RESOLVED = "RESOLVED"
|
|
180
|
+
|
|
181
|
+
assert Opt(AnalysisAnalysisState.RESOLVED).map_key("value").get() == "RESOLVED"
|
|
@@ -141,7 +141,6 @@ def test_string_one():
|
|
|
141
141
|
def test_string_one_ends():
|
|
142
142
|
stream = Stream("H")
|
|
143
143
|
assert stream.next().get() == "H"
|
|
144
|
-
assert stream.next().empty is True
|
|
145
144
|
|
|
146
145
|
|
|
147
146
|
def test_list_flatmap_count():
|
|
@@ -317,7 +316,7 @@ def test_object_list_filter_key_invert():
|
|
|
317
316
|
|
|
318
317
|
def test_object_list_map_key():
|
|
319
318
|
stream = Stream(create_list())
|
|
320
|
-
assert stream.
|
|
319
|
+
assert stream.kmap("name").join(":") == "Parent A:Parent B"
|
|
321
320
|
|
|
322
321
|
|
|
323
322
|
def test_object_dict_map_key():
|
|
@@ -361,7 +360,7 @@ def test_dict_map_key():
|
|
|
361
360
|
|
|
362
361
|
def test_dict_filter_key_invert():
|
|
363
362
|
stream = Stream.of_dict(create_dict())
|
|
364
|
-
assert stream.filter_key(0, invert=True).next().
|
|
363
|
+
assert stream.filter_key(0, invert=True).next().absent
|
|
365
364
|
|
|
366
365
|
|
|
367
366
|
def test_dict_map_value():
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tinystream
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.18
|
|
4
4
|
Summary: Yet another python streams library
|
|
5
5
|
Home-page: https://github.com/mreiche/python-streams
|
|
6
6
|
Author: Mike Reiche
|
|
@@ -13,8 +13,9 @@ Dynamic: home-page
|
|
|
13
13
|
Dynamic: license-file
|
|
14
14
|
Dynamic: summary
|
|
15
15
|
|
|
16
|
-

|
|
16
|
+
[](https://github.com/mreiche/python-streams/actions/workflows/tests.yml)
|
|
17
17
|
[](https://app.codecov.io/github/mreiche/python-streams)
|
|
18
|
+
[](https://badge.fury.io/py/tinystream)
|
|
18
19
|
|
|
19
20
|
# tinystream / python-streams
|
|
20
21
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import enum
|
|
1
2
|
import functools
|
|
2
3
|
import itertools
|
|
3
4
|
from typing import Iterable, TypeVar, Callable, List, Dict, Tuple, Iterator, Generic, Type
|
|
4
|
-
from warnings import warn
|
|
5
5
|
|
|
6
6
|
T = TypeVar("T")
|
|
7
7
|
R = TypeVar("R")
|
|
@@ -19,22 +19,27 @@ Key = int|str
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def _key_exists(x: any, key: Key, invert: bool = False):
|
|
22
|
+
def _hasattr():
|
|
23
|
+
if invert:
|
|
24
|
+
return not hasattr(x, key)
|
|
25
|
+
else:
|
|
26
|
+
return hasattr(x, key)
|
|
27
|
+
|
|
22
28
|
if isinstance(x, (list, tuple)):
|
|
23
29
|
size = len(x)
|
|
24
30
|
if invert:
|
|
25
31
|
return key >= size
|
|
26
32
|
else:
|
|
27
33
|
return key < size
|
|
34
|
+
elif isinstance(x, enum.Enum):
|
|
35
|
+
return _hasattr()
|
|
28
36
|
elif isinstance(x, (dict, Iterable)):
|
|
29
37
|
if invert:
|
|
30
38
|
return key not in x
|
|
31
39
|
else:
|
|
32
40
|
return key in x
|
|
33
41
|
else:
|
|
34
|
-
|
|
35
|
-
return not hasattr(x, key)
|
|
36
|
-
else:
|
|
37
|
-
return hasattr(x, key)
|
|
42
|
+
return _hasattr()
|
|
38
43
|
|
|
39
44
|
|
|
40
45
|
def _get_key_value(x: any, key: Key) -> any:
|
|
@@ -48,11 +53,6 @@ class Opt(Generic[T]):
|
|
|
48
53
|
def __init__(self, value: T):
|
|
49
54
|
self.__val = value
|
|
50
55
|
|
|
51
|
-
@property
|
|
52
|
-
def empty(self):
|
|
53
|
-
warn("Please use absent property instead", DeprecationWarning)
|
|
54
|
-
return self.absent
|
|
55
|
-
|
|
56
56
|
@property
|
|
57
57
|
def absent(self):
|
|
58
58
|
return self.__val is None
|
|
@@ -88,10 +88,6 @@ class Opt(Generic[T]):
|
|
|
88
88
|
else:
|
|
89
89
|
return Opt[R](mapper(self.__val))
|
|
90
90
|
|
|
91
|
-
def if_empty(self, supplier: Supplier[R] | any):
|
|
92
|
-
warn("Please use if_absent() method instead", DeprecationWarning)
|
|
93
|
-
return self.if_absent(supplier)
|
|
94
|
-
|
|
95
91
|
def if_absent(self, supplier: Supplier[R] | any):
|
|
96
92
|
if self.absent:
|
|
97
93
|
if isinstance(supplier, Callable):
|
|
@@ -187,11 +183,6 @@ class Stream(Iterator[T]):
|
|
|
187
183
|
self.__collected: List[T] = None
|
|
188
184
|
self.__on_end: Callable = None
|
|
189
185
|
|
|
190
|
-
@staticmethod
|
|
191
|
-
def of(iterable: Iterable[T]):
|
|
192
|
-
warn("Use constructor", DeprecationWarning)
|
|
193
|
-
return Stream[T](iterable)
|
|
194
|
-
|
|
195
186
|
@staticmethod
|
|
196
187
|
def of_dict(source_dict: Dict[K, T]):
|
|
197
188
|
return Stream[Tuple[K, T]](source_dict)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|