tinystream 0.1.17__tar.gz → 1.0.0__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-1.0.0}/PKG-INFO +20 -18
- {tinystream-0.1.17 → tinystream-1.0.0}/README.md +18 -16
- {tinystream-0.1.17 → tinystream-1.0.0}/setup.py +1 -1
- {tinystream-0.1.17 → tinystream-1.0.0}/tests/test_opt.py +12 -3
- {tinystream-0.1.17 → tinystream-1.0.0}/tests/test_streams.py +2 -3
- {tinystream-0.1.17 → tinystream-1.0.0/tinystream.egg-info}/PKG-INFO +20 -18
- {tinystream-0.1.17 → tinystream-1.0.0}/tinystream.py +10 -19
- {tinystream-0.1.17 → tinystream-1.0.0}/LICENSE +0 -0
- {tinystream-0.1.17 → tinystream-1.0.0}/setup.cfg +0 -0
- {tinystream-0.1.17 → tinystream-1.0.0}/tinystream.egg-info/SOURCES.txt +0 -0
- {tinystream-0.1.17 → tinystream-1.0.0}/tinystream.egg-info/dependency_links.txt +0 -0
- {tinystream-0.1.17 → tinystream-1.0.0}/tinystream.egg-info/top_level.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tinystream
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Yet another python streams library
|
|
5
|
-
Home-page: https://github.com/mreiche/
|
|
5
|
+
Home-page: https://github.com/mreiche/tinystream
|
|
6
6
|
Author: Mike Reiche
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
License-File: LICENSE
|
|
@@ -13,14 +13,13 @@ Dynamic: home-page
|
|
|
13
13
|
Dynamic: license-file
|
|
14
14
|
Dynamic: summary
|
|
15
15
|
|
|
16
|
-
](https://github.com/mreiche/tinystream/actions/workflows/tests.yml)
|
|
17
|
+
[](https://app.codecov.io/github/mreiche/tinystream)
|
|
18
|
+
[](https://badge.fury.io/py/tinystream)
|
|
18
19
|
|
|
19
|
-
# tinystream
|
|
20
|
+
# tinystream
|
|
20
21
|
|
|
21
|
-
This is a
|
|
22
|
-
|
|
23
|
-
This package is released as `tinystream` at pypi.
|
|
22
|
+
This is a tiny, lightweight and simple Streams API inspired by Java Streams with support for type hinting.
|
|
24
23
|
|
|
25
24
|
## Basic API
|
|
26
25
|
|
|
@@ -29,14 +28,17 @@ from tinystream import Stream
|
|
|
29
28
|
|
|
30
29
|
stream = Stream([1, 2, 3, 4, 5]) # Stream.of_many(*), Stream.of_dict()
|
|
31
30
|
|
|
31
|
+
for item in stream:
|
|
32
|
+
pass
|
|
33
|
+
|
|
32
34
|
stream \
|
|
33
|
-
.map(lambda x: x + 1) \
|
|
34
|
-
.filter(lambda x: x > 2) \
|
|
35
|
-
.sorted(reverse=True) \
|
|
35
|
+
.map(lambda x: x + 1) \ # flatmap(), peek(), map_key(), map_kwargs(), map_keys()
|
|
36
|
+
.filter(lambda x: x > 2) \ # filter_key(), filter_type()
|
|
37
|
+
.sorted(reverse=True) \ # sort()
|
|
36
38
|
.reverse() \
|
|
37
39
|
.limit(2) \
|
|
38
|
-
.concat([4]) \
|
|
39
|
-
.sum()
|
|
40
|
+
.concat([4, 6]) \
|
|
41
|
+
.sum() # reduce(), max(), min(), collect(), count(), find()
|
|
40
42
|
```
|
|
41
43
|
|
|
42
44
|
## Aggregators
|
|
@@ -165,7 +167,7 @@ if char == "a":
|
|
|
165
167
|
|
|
166
168
|
### Opt usage
|
|
167
169
|
|
|
168
|
-
Get next value as `Opt`:
|
|
170
|
+
Get the next value as `Opt`:
|
|
169
171
|
|
|
170
172
|
```python
|
|
171
173
|
assert Stream((1, 2, 3, 4, 5)).next().present
|
|
@@ -205,11 +207,11 @@ data = {
|
|
|
205
207
|
]
|
|
206
208
|
}
|
|
207
209
|
|
|
208
|
-
# With tinystream
|
|
210
|
+
# With tinystream
|
|
209
211
|
for range_data in Opt(data).map_key("ranges").stream().map_kwargs(timedelta):
|
|
210
212
|
pass
|
|
211
213
|
|
|
212
|
-
#
|
|
214
|
+
# Vanilla Python
|
|
213
215
|
if "ranges" in data:
|
|
214
216
|
range_data: timedelta
|
|
215
217
|
for range_data in map(lambda x: timedelta(**x), data["ranges"]):
|
|
@@ -218,7 +220,7 @@ if "ranges" in data:
|
|
|
218
220
|
|
|
219
221
|
### Write better code with `Opt`
|
|
220
222
|
```python
|
|
221
|
-
# tinystream
|
|
223
|
+
# With tinystream
|
|
222
224
|
var = Opt(my_dict).kmap("key").filter(not_empty).get("default")
|
|
223
225
|
|
|
224
226
|
# Vanilla Python
|
|
@@ -228,7 +230,7 @@ var = my_dict["key"] if "key" in my_dict and not_empty(my_dict["key"]) else "def
|
|
|
228
230
|
|
|
229
231
|
## Comparison with other libraries
|
|
230
232
|
|
|
231
|
-
There are a couple of other
|
|
233
|
+
There are a couple of other implementations to fulfill similar requirements.
|
|
232
234
|
|
|
233
235
|
- https://github.com/vxgmichel/aiostream
|
|
234
236
|
- https://github.com/python-streamz/streamz
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
](https://github.com/mreiche/tinystream/actions/workflows/tests.yml)
|
|
2
|
+
[](https://app.codecov.io/github/mreiche/tinystream)
|
|
3
|
+
[](https://badge.fury.io/py/tinystream)
|
|
3
4
|
|
|
4
|
-
# tinystream
|
|
5
|
+
# tinystream
|
|
5
6
|
|
|
6
|
-
This is a
|
|
7
|
-
|
|
8
|
-
This package is released as `tinystream` at pypi.
|
|
7
|
+
This is a tiny, lightweight and simple Streams API inspired by Java Streams with support for type hinting.
|
|
9
8
|
|
|
10
9
|
## Basic API
|
|
11
10
|
|
|
@@ -14,14 +13,17 @@ from tinystream import Stream
|
|
|
14
13
|
|
|
15
14
|
stream = Stream([1, 2, 3, 4, 5]) # Stream.of_many(*), Stream.of_dict()
|
|
16
15
|
|
|
16
|
+
for item in stream:
|
|
17
|
+
pass
|
|
18
|
+
|
|
17
19
|
stream \
|
|
18
|
-
.map(lambda x: x + 1) \
|
|
19
|
-
.filter(lambda x: x > 2) \
|
|
20
|
-
.sorted(reverse=True) \
|
|
20
|
+
.map(lambda x: x + 1) \ # flatmap(), peek(), map_key(), map_kwargs(), map_keys()
|
|
21
|
+
.filter(lambda x: x > 2) \ # filter_key(), filter_type()
|
|
22
|
+
.sorted(reverse=True) \ # sort()
|
|
21
23
|
.reverse() \
|
|
22
24
|
.limit(2) \
|
|
23
|
-
.concat([4]) \
|
|
24
|
-
.sum()
|
|
25
|
+
.concat([4, 6]) \
|
|
26
|
+
.sum() # reduce(), max(), min(), collect(), count(), find()
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
## Aggregators
|
|
@@ -150,7 +152,7 @@ if char == "a":
|
|
|
150
152
|
|
|
151
153
|
### Opt usage
|
|
152
154
|
|
|
153
|
-
Get next value as `Opt`:
|
|
155
|
+
Get the next value as `Opt`:
|
|
154
156
|
|
|
155
157
|
```python
|
|
156
158
|
assert Stream((1, 2, 3, 4, 5)).next().present
|
|
@@ -190,11 +192,11 @@ data = {
|
|
|
190
192
|
]
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
# With tinystream
|
|
195
|
+
# With tinystream
|
|
194
196
|
for range_data in Opt(data).map_key("ranges").stream().map_kwargs(timedelta):
|
|
195
197
|
pass
|
|
196
198
|
|
|
197
|
-
#
|
|
199
|
+
# Vanilla Python
|
|
198
200
|
if "ranges" in data:
|
|
199
201
|
range_data: timedelta
|
|
200
202
|
for range_data in map(lambda x: timedelta(**x), data["ranges"]):
|
|
@@ -203,7 +205,7 @@ if "ranges" in data:
|
|
|
203
205
|
|
|
204
206
|
### Write better code with `Opt`
|
|
205
207
|
```python
|
|
206
|
-
# tinystream
|
|
208
|
+
# With tinystream
|
|
207
209
|
var = Opt(my_dict).kmap("key").filter(not_empty).get("default")
|
|
208
210
|
|
|
209
211
|
# Vanilla Python
|
|
@@ -213,7 +215,7 @@ var = my_dict["key"] if "key" in my_dict and not_empty(my_dict["key"]) else "def
|
|
|
213
215
|
|
|
214
216
|
## Comparison with other libraries
|
|
215
217
|
|
|
216
|
-
There are a couple of other
|
|
218
|
+
There are a couple of other implementations to fulfill similar requirements.
|
|
217
219
|
|
|
218
220
|
- https://github.com/vxgmichel/aiostream
|
|
219
221
|
- https://github.com/python-streamz/streamz
|
|
@@ -14,7 +14,7 @@ setup(
|
|
|
14
14
|
long_description=long_description,
|
|
15
15
|
long_description_content_type="text/markdown",
|
|
16
16
|
version=VERSION,
|
|
17
|
-
url="https://github.com/mreiche/
|
|
17
|
+
url="https://github.com/mreiche/tinystream",
|
|
18
18
|
author="Mike Reiche",
|
|
19
19
|
py_modules=['tinystream'],
|
|
20
20
|
install_requires=[],
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tinystream
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Yet another python streams library
|
|
5
|
-
Home-page: https://github.com/mreiche/
|
|
5
|
+
Home-page: https://github.com/mreiche/tinystream
|
|
6
6
|
Author: Mike Reiche
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
License-File: LICENSE
|
|
@@ -13,14 +13,13 @@ Dynamic: home-page
|
|
|
13
13
|
Dynamic: license-file
|
|
14
14
|
Dynamic: summary
|
|
15
15
|
|
|
16
|
-
](https://github.com/mreiche/tinystream/actions/workflows/tests.yml)
|
|
17
|
+
[](https://app.codecov.io/github/mreiche/tinystream)
|
|
18
|
+
[](https://badge.fury.io/py/tinystream)
|
|
18
19
|
|
|
19
|
-
# tinystream
|
|
20
|
+
# tinystream
|
|
20
21
|
|
|
21
|
-
This is a
|
|
22
|
-
|
|
23
|
-
This package is released as `tinystream` at pypi.
|
|
22
|
+
This is a tiny, lightweight and simple Streams API inspired by Java Streams with support for type hinting.
|
|
24
23
|
|
|
25
24
|
## Basic API
|
|
26
25
|
|
|
@@ -29,14 +28,17 @@ from tinystream import Stream
|
|
|
29
28
|
|
|
30
29
|
stream = Stream([1, 2, 3, 4, 5]) # Stream.of_many(*), Stream.of_dict()
|
|
31
30
|
|
|
31
|
+
for item in stream:
|
|
32
|
+
pass
|
|
33
|
+
|
|
32
34
|
stream \
|
|
33
|
-
.map(lambda x: x + 1) \
|
|
34
|
-
.filter(lambda x: x > 2) \
|
|
35
|
-
.sorted(reverse=True) \
|
|
35
|
+
.map(lambda x: x + 1) \ # flatmap(), peek(), map_key(), map_kwargs(), map_keys()
|
|
36
|
+
.filter(lambda x: x > 2) \ # filter_key(), filter_type()
|
|
37
|
+
.sorted(reverse=True) \ # sort()
|
|
36
38
|
.reverse() \
|
|
37
39
|
.limit(2) \
|
|
38
|
-
.concat([4]) \
|
|
39
|
-
.sum()
|
|
40
|
+
.concat([4, 6]) \
|
|
41
|
+
.sum() # reduce(), max(), min(), collect(), count(), find()
|
|
40
42
|
```
|
|
41
43
|
|
|
42
44
|
## Aggregators
|
|
@@ -165,7 +167,7 @@ if char == "a":
|
|
|
165
167
|
|
|
166
168
|
### Opt usage
|
|
167
169
|
|
|
168
|
-
Get next value as `Opt`:
|
|
170
|
+
Get the next value as `Opt`:
|
|
169
171
|
|
|
170
172
|
```python
|
|
171
173
|
assert Stream((1, 2, 3, 4, 5)).next().present
|
|
@@ -205,11 +207,11 @@ data = {
|
|
|
205
207
|
]
|
|
206
208
|
}
|
|
207
209
|
|
|
208
|
-
# With tinystream
|
|
210
|
+
# With tinystream
|
|
209
211
|
for range_data in Opt(data).map_key("ranges").stream().map_kwargs(timedelta):
|
|
210
212
|
pass
|
|
211
213
|
|
|
212
|
-
#
|
|
214
|
+
# Vanilla Python
|
|
213
215
|
if "ranges" in data:
|
|
214
216
|
range_data: timedelta
|
|
215
217
|
for range_data in map(lambda x: timedelta(**x), data["ranges"]):
|
|
@@ -218,7 +220,7 @@ if "ranges" in data:
|
|
|
218
220
|
|
|
219
221
|
### Write better code with `Opt`
|
|
220
222
|
```python
|
|
221
|
-
# tinystream
|
|
223
|
+
# With tinystream
|
|
222
224
|
var = Opt(my_dict).kmap("key").filter(not_empty).get("default")
|
|
223
225
|
|
|
224
226
|
# Vanilla Python
|
|
@@ -228,7 +230,7 @@ var = my_dict["key"] if "key" in my_dict and not_empty(my_dict["key"]) else "def
|
|
|
228
230
|
|
|
229
231
|
## Comparison with other libraries
|
|
230
232
|
|
|
231
|
-
There are a couple of other
|
|
233
|
+
There are a couple of other implementations to fulfill similar requirements.
|
|
232
234
|
|
|
233
235
|
- https://github.com/vxgmichel/aiostream
|
|
234
236
|
- https://github.com/python-streamz/streamz
|
|
@@ -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
|