tinystream 0.1.14__tar.gz → 0.1.16__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.14/tinystream.egg-info → tinystream-0.1.16}/PKG-INFO +15 -8
- {tinystream-0.1.14 → tinystream-0.1.16}/README.md +14 -7
- {tinystream-0.1.14 → tinystream-0.1.16}/setup.py +1 -1
- {tinystream-0.1.14 → tinystream-0.1.16/tinystream.egg-info}/PKG-INFO +15 -8
- {tinystream-0.1.14 → tinystream-0.1.16}/tinystream.py +28 -15
- {tinystream-0.1.14 → tinystream-0.1.16}/LICENSE +0 -0
- {tinystream-0.1.14 → tinystream-0.1.16}/setup.cfg +0 -0
- {tinystream-0.1.14 → tinystream-0.1.16}/tinystream.egg-info/SOURCES.txt +0 -0
- {tinystream-0.1.14 → tinystream-0.1.16}/tinystream.egg-info/dependency_links.txt +0 -0
- {tinystream-0.1.14 → tinystream-0.1.16}/tinystream.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tinystream
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.16
|
|
4
4
|
Summary: Yet another python streams library
|
|
5
5
|
Home-page: https://github.com/mreiche/python-streams
|
|
6
6
|
Author: Mike Reiche
|
|
@@ -14,7 +14,7 @@ License-File: LICENSE
|
|
|
14
14
|
|
|
15
15
|
This is a simple and lightweight Streams API inspired by Java Streams with support for type hinting.
|
|
16
16
|
|
|
17
|
-
This package is
|
|
17
|
+
This package is released as `tinystream` at pypi.
|
|
18
18
|
|
|
19
19
|
## Basic API
|
|
20
20
|
|
|
@@ -137,6 +137,11 @@ stream = Stream(children)
|
|
|
137
137
|
items_with_name = Stream([child]).filter_key("name")
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
+
### Filter by key value
|
|
141
|
+
```python
|
|
142
|
+
items_with_name = Stream([child]).filter_key_value("name", "Child")
|
|
143
|
+
```
|
|
144
|
+
|
|
140
145
|
### Filter by type
|
|
141
146
|
```python
|
|
142
147
|
nodes_only = Stream([child]).filter_type(Node)
|
|
@@ -195,7 +200,8 @@ A given data structure like:
|
|
|
195
200
|
```python
|
|
196
201
|
data = {
|
|
197
202
|
"ranges": [
|
|
198
|
-
|
|
203
|
+
{"days": 3},
|
|
204
|
+
{"weeks": 1},
|
|
199
205
|
]
|
|
200
206
|
}
|
|
201
207
|
```
|
|
@@ -204,13 +210,13 @@ Without tinystream:
|
|
|
204
210
|
```python
|
|
205
211
|
if "ranges" in data:
|
|
206
212
|
range_data: timedelta
|
|
207
|
-
for range_data in
|
|
213
|
+
for range_data in map(lambda x: timedelta(**x), data["ranges"]):
|
|
208
214
|
pass
|
|
209
215
|
```
|
|
210
216
|
|
|
211
217
|
With tinystream:
|
|
212
218
|
```python
|
|
213
|
-
for range_data in Opt(data).map_key("ranges").stream().
|
|
219
|
+
for range_data in Opt(data).map_key("ranges").stream().map_kwargs(timedelta):
|
|
214
220
|
pass
|
|
215
221
|
```
|
|
216
222
|
|
|
@@ -218,10 +224,11 @@ for range_data in Opt(data).map_key("ranges").stream().filter_type(timedelta):
|
|
|
218
224
|
|
|
219
225
|
There are a couple of other implementation to fulfill similar requirements.
|
|
220
226
|
|
|
221
|
-
- https://github.com/vxgmichel/aiostream
|
|
222
|
-
- https://github.com/
|
|
223
|
-
- https://github.com/ramsteak/streams
|
|
227
|
+
- https://github.com/vxgmichel/aiostream
|
|
228
|
+
- https://github.com/python-streamz/streamz
|
|
224
229
|
- https://pypi.org/project/fluentpy
|
|
230
|
+
- https://github.com/ramsteak/streams
|
|
231
|
+
- https://github.com/alemazzo/Python-Java-Stream (*outdated*)
|
|
225
232
|
- https://github.com/JaviOverflow/python-streams (*outdated*)
|
|
226
233
|
- https://github.com/9seconds/streams/ (*outdated*)
|
|
227
234
|
- https://github.com/tolsac/streampy (*outdated*)
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
This is a simple and lightweight Streams API inspired by Java Streams with support for type hinting.
|
|
7
7
|
|
|
8
|
-
This package is
|
|
8
|
+
This package is released as `tinystream` at pypi.
|
|
9
9
|
|
|
10
10
|
## Basic API
|
|
11
11
|
|
|
@@ -128,6 +128,11 @@ stream = Stream(children)
|
|
|
128
128
|
items_with_name = Stream([child]).filter_key("name")
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
### Filter by key value
|
|
132
|
+
```python
|
|
133
|
+
items_with_name = Stream([child]).filter_key_value("name", "Child")
|
|
134
|
+
```
|
|
135
|
+
|
|
131
136
|
### Filter by type
|
|
132
137
|
```python
|
|
133
138
|
nodes_only = Stream([child]).filter_type(Node)
|
|
@@ -186,7 +191,8 @@ A given data structure like:
|
|
|
186
191
|
```python
|
|
187
192
|
data = {
|
|
188
193
|
"ranges": [
|
|
189
|
-
|
|
194
|
+
{"days": 3},
|
|
195
|
+
{"weeks": 1},
|
|
190
196
|
]
|
|
191
197
|
}
|
|
192
198
|
```
|
|
@@ -195,13 +201,13 @@ Without tinystream:
|
|
|
195
201
|
```python
|
|
196
202
|
if "ranges" in data:
|
|
197
203
|
range_data: timedelta
|
|
198
|
-
for range_data in
|
|
204
|
+
for range_data in map(lambda x: timedelta(**x), data["ranges"]):
|
|
199
205
|
pass
|
|
200
206
|
```
|
|
201
207
|
|
|
202
208
|
With tinystream:
|
|
203
209
|
```python
|
|
204
|
-
for range_data in Opt(data).map_key("ranges").stream().
|
|
210
|
+
for range_data in Opt(data).map_key("ranges").stream().map_kwargs(timedelta):
|
|
205
211
|
pass
|
|
206
212
|
```
|
|
207
213
|
|
|
@@ -209,10 +215,11 @@ for range_data in Opt(data).map_key("ranges").stream().filter_type(timedelta):
|
|
|
209
215
|
|
|
210
216
|
There are a couple of other implementation to fulfill similar requirements.
|
|
211
217
|
|
|
212
|
-
- https://github.com/vxgmichel/aiostream
|
|
213
|
-
- https://github.com/
|
|
214
|
-
- https://github.com/ramsteak/streams
|
|
218
|
+
- https://github.com/vxgmichel/aiostream
|
|
219
|
+
- https://github.com/python-streamz/streamz
|
|
215
220
|
- https://pypi.org/project/fluentpy
|
|
221
|
+
- https://github.com/ramsteak/streams
|
|
222
|
+
- https://github.com/alemazzo/Python-Java-Stream (*outdated*)
|
|
216
223
|
- https://github.com/JaviOverflow/python-streams (*outdated*)
|
|
217
224
|
- https://github.com/9seconds/streams/ (*outdated*)
|
|
218
225
|
- https://github.com/tolsac/streampy (*outdated*)
|
|
@@ -10,7 +10,7 @@ setup(
|
|
|
10
10
|
description="Yet another python streams library",
|
|
11
11
|
long_description=long_description,
|
|
12
12
|
long_description_content_type="text/markdown",
|
|
13
|
-
version="0.1.
|
|
13
|
+
version="0.1.16",
|
|
14
14
|
url="https://github.com/mreiche/python-streams",
|
|
15
15
|
author="Mike Reiche",
|
|
16
16
|
py_modules=['tinystream'],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tinystream
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.16
|
|
4
4
|
Summary: Yet another python streams library
|
|
5
5
|
Home-page: https://github.com/mreiche/python-streams
|
|
6
6
|
Author: Mike Reiche
|
|
@@ -14,7 +14,7 @@ License-File: LICENSE
|
|
|
14
14
|
|
|
15
15
|
This is a simple and lightweight Streams API inspired by Java Streams with support for type hinting.
|
|
16
16
|
|
|
17
|
-
This package is
|
|
17
|
+
This package is released as `tinystream` at pypi.
|
|
18
18
|
|
|
19
19
|
## Basic API
|
|
20
20
|
|
|
@@ -137,6 +137,11 @@ stream = Stream(children)
|
|
|
137
137
|
items_with_name = Stream([child]).filter_key("name")
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
+
### Filter by key value
|
|
141
|
+
```python
|
|
142
|
+
items_with_name = Stream([child]).filter_key_value("name", "Child")
|
|
143
|
+
```
|
|
144
|
+
|
|
140
145
|
### Filter by type
|
|
141
146
|
```python
|
|
142
147
|
nodes_only = Stream([child]).filter_type(Node)
|
|
@@ -195,7 +200,8 @@ A given data structure like:
|
|
|
195
200
|
```python
|
|
196
201
|
data = {
|
|
197
202
|
"ranges": [
|
|
198
|
-
|
|
203
|
+
{"days": 3},
|
|
204
|
+
{"weeks": 1},
|
|
199
205
|
]
|
|
200
206
|
}
|
|
201
207
|
```
|
|
@@ -204,13 +210,13 @@ Without tinystream:
|
|
|
204
210
|
```python
|
|
205
211
|
if "ranges" in data:
|
|
206
212
|
range_data: timedelta
|
|
207
|
-
for range_data in
|
|
213
|
+
for range_data in map(lambda x: timedelta(**x), data["ranges"]):
|
|
208
214
|
pass
|
|
209
215
|
```
|
|
210
216
|
|
|
211
217
|
With tinystream:
|
|
212
218
|
```python
|
|
213
|
-
for range_data in Opt(data).map_key("ranges").stream().
|
|
219
|
+
for range_data in Opt(data).map_key("ranges").stream().map_kwargs(timedelta):
|
|
214
220
|
pass
|
|
215
221
|
```
|
|
216
222
|
|
|
@@ -218,10 +224,11 @@ for range_data in Opt(data).map_key("ranges").stream().filter_type(timedelta):
|
|
|
218
224
|
|
|
219
225
|
There are a couple of other implementation to fulfill similar requirements.
|
|
220
226
|
|
|
221
|
-
- https://github.com/vxgmichel/aiostream
|
|
222
|
-
- https://github.com/
|
|
223
|
-
- https://github.com/ramsteak/streams
|
|
227
|
+
- https://github.com/vxgmichel/aiostream
|
|
228
|
+
- https://github.com/python-streamz/streamz
|
|
224
229
|
- https://pypi.org/project/fluentpy
|
|
230
|
+
- https://github.com/ramsteak/streams
|
|
231
|
+
- https://github.com/alemazzo/Python-Java-Stream (*outdated*)
|
|
225
232
|
- https://github.com/JaviOverflow/python-streams (*outdated*)
|
|
226
233
|
- https://github.com/9seconds/streams/ (*outdated*)
|
|
227
234
|
- https://github.com/tolsac/streampy (*outdated*)
|
|
@@ -8,16 +8,17 @@ R = TypeVar("R")
|
|
|
8
8
|
K = TypeVar("K")
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Mapper = Callable[[T], R]
|
|
11
|
+
Mapper = Callable[[T], R] | Type[R]
|
|
12
12
|
FlatMapper = Callable[[T], Iterable[R]]
|
|
13
13
|
Consumer = Callable[[T], None]
|
|
14
14
|
Comparator = Callable[[T, T], bool]
|
|
15
15
|
Reducer = Callable[[T, T], R]
|
|
16
16
|
Predicate = Callable[[T], bool]
|
|
17
17
|
Supplier = Callable[[], T]
|
|
18
|
+
Key = int|str
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
def
|
|
21
|
+
def _key_exists(x: any, key: Key, invert: bool = False):
|
|
21
22
|
if isinstance(x, (list, tuple)):
|
|
22
23
|
size = len(x)
|
|
23
24
|
if invert:
|
|
@@ -36,7 +37,7 @@ def _filter_key(x: any, key: any, invert: bool = False):
|
|
|
36
37
|
return hasattr(x, key)
|
|
37
38
|
|
|
38
39
|
|
|
39
|
-
def
|
|
40
|
+
def _get_key_value(x: any, key: Key) -> any:
|
|
40
41
|
if isinstance(x, (list, dict, tuple)):
|
|
41
42
|
return x[key]
|
|
42
43
|
else:
|
|
@@ -81,7 +82,7 @@ class Opt(Generic[T]):
|
|
|
81
82
|
else:
|
|
82
83
|
return EmptyOpt()
|
|
83
84
|
|
|
84
|
-
def map(self, mapper: Mapper[T, R]):
|
|
85
|
+
def map(self, mapper: Mapper[T, R]) -> "Opt[R]":
|
|
85
86
|
if self.absent:
|
|
86
87
|
return EmptyOpt()
|
|
87
88
|
else:
|
|
@@ -106,15 +107,21 @@ class Opt(Generic[T]):
|
|
|
106
107
|
def filter_type(self, typehint: Type[R]) -> "Opt[R]":
|
|
107
108
|
return self.filter(lambda x: isinstance(x, typehint))
|
|
108
109
|
|
|
109
|
-
def filter_key(self, key:
|
|
110
|
-
if
|
|
110
|
+
def filter_key(self, key: Key, invert: bool = False):
|
|
111
|
+
if _key_exists(self.__val, key, invert):
|
|
112
|
+
return self
|
|
113
|
+
else:
|
|
114
|
+
return EmptyOpt()
|
|
115
|
+
|
|
116
|
+
def filter_key_value(self, key: Key, value: any):
|
|
117
|
+
if _key_exists(self.__val, key, False) and _get_key_value(self.__val, key) == value:
|
|
111
118
|
return self
|
|
112
119
|
else:
|
|
113
120
|
return EmptyOpt()
|
|
114
121
|
|
|
115
|
-
def map_key(self, key:
|
|
116
|
-
if
|
|
117
|
-
return Opt(
|
|
122
|
+
def map_key(self, key: Key):
|
|
123
|
+
if _key_exists(self.__val, key):
|
|
124
|
+
return Opt(_get_key_value(self.__val, key))
|
|
118
125
|
else:
|
|
119
126
|
return EmptyOpt()
|
|
120
127
|
|
|
@@ -148,10 +155,13 @@ class EmptyOpt(Opt[None]):
|
|
|
148
155
|
def filter(self, predicate: Predicate[T]):
|
|
149
156
|
return self
|
|
150
157
|
|
|
151
|
-
def map_key(self, key:
|
|
158
|
+
def map_key(self, key: Key):
|
|
159
|
+
return self
|
|
160
|
+
|
|
161
|
+
def filter_key(self, key: Key, invert: bool = False):
|
|
152
162
|
return self
|
|
153
163
|
|
|
154
|
-
def
|
|
164
|
+
def filter_key_value(self, key: Key, value: any):
|
|
155
165
|
return self
|
|
156
166
|
|
|
157
167
|
@property
|
|
@@ -224,8 +234,8 @@ class Stream(Iterator[T]):
|
|
|
224
234
|
def map_kwargs(self, mapper: Type[R]) -> "Stream[R]":
|
|
225
235
|
return self.map(lambda x: mapper(**x))
|
|
226
236
|
|
|
227
|
-
def map_key(self, key:
|
|
228
|
-
return self.filter_key(key).map(lambda x:
|
|
237
|
+
def map_key(self, key: Key):
|
|
238
|
+
return self.filter_key(key).map(lambda x: _get_key_value(x, key))
|
|
229
239
|
|
|
230
240
|
def map_keys(self, *iterables):
|
|
231
241
|
inst = self
|
|
@@ -242,8 +252,11 @@ class Stream(Iterator[T]):
|
|
|
242
252
|
def filter(self, predicate: Predicate[T]):
|
|
243
253
|
return Stream[T](filter(predicate, self.__iterable))
|
|
244
254
|
|
|
245
|
-
def filter_key(self, key:
|
|
246
|
-
return self.filter(lambda x:
|
|
255
|
+
def filter_key(self, key: Key, invert: bool = False):
|
|
256
|
+
return self.filter(lambda x: _key_exists(x, key, invert))
|
|
257
|
+
|
|
258
|
+
def filter_key_value(self, key: Key, value: any):
|
|
259
|
+
return self.filter(lambda x: _key_exists(x, key, False) and _get_key_value(x, key) == value)
|
|
247
260
|
|
|
248
261
|
def flatmap(self, mapper: FlatMapper[T, R] = None):
|
|
249
262
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|