tinystream 0.1.11__tar.gz → 0.1.13__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinystream
3
- Version: 0.1.11
3
+ Version: 0.1.13
4
4
  Summary: Yet another python streams library
5
5
  Home-page: https://github.com/mreiche/python-streams
6
6
  Author: Mike Reiche
@@ -24,9 +24,9 @@ from tinystream import Stream
24
24
  stream = Stream([1, 2, 3, 4, 5]) # Stream.of_many(*), Stream.of_dict()
25
25
 
26
26
  stream \
27
- .map(lambda x: x + 1) \ # flatmap(), peek(), map_key()
27
+ .map(lambda x: x + 1) \ # flatmap(), peek(), map_key(), map_kwargs(), map_keys()
28
28
  .filter(lambda x: x > 2) \ # filter_key(), filter_type()
29
- .sorted(int, reverse=True) \ # sort()
29
+ .sorted(reverse=True) \ # sort()
30
30
  .reverse() \
31
31
  .limit(2) \
32
32
  .concat([4]) \
@@ -61,7 +61,7 @@ assert Opt(None).absent
61
61
 
62
62
  Map *optional*:
63
63
  ```python
64
- assert Opt("String").map(len).get() == 6
64
+ assert Opt("String").map(str.lower).len == 6
65
65
  ```
66
66
 
67
67
  Get default value:
@@ -155,7 +155,7 @@ list = [
155
155
  {"node": Node(name="Node C")},
156
156
  {"node": Node(name="Node D")},
157
157
  ]
158
- Stream(list).map_keys("node", "name")
158
+ names = Stream(list).map_keys("node", "name")
159
159
  ```
160
160
 
161
161
  ### Collected join
@@ -164,6 +164,16 @@ Stream(list).map_keys("node", "name")
164
164
  all_names = Stream([child]).map_key("name").join(", ")
165
165
  ```
166
166
 
167
+ ### Map kwargs
168
+ ```python
169
+ list = [
170
+ {"name": "Node A"},
171
+ {"name": "Node B"},
172
+ ]
173
+ # Short cut for map(lambda x: Node(**x))
174
+ nodes = Stream(list).map_kwargs(Node)
175
+ ```
176
+
167
177
  ### Stream many
168
178
 
169
179
  ```python
@@ -15,9 +15,9 @@ from tinystream import Stream
15
15
  stream = Stream([1, 2, 3, 4, 5]) # Stream.of_many(*), Stream.of_dict()
16
16
 
17
17
  stream \
18
- .map(lambda x: x + 1) \ # flatmap(), peek(), map_key()
18
+ .map(lambda x: x + 1) \ # flatmap(), peek(), map_key(), map_kwargs(), map_keys()
19
19
  .filter(lambda x: x > 2) \ # filter_key(), filter_type()
20
- .sorted(int, reverse=True) \ # sort()
20
+ .sorted(reverse=True) \ # sort()
21
21
  .reverse() \
22
22
  .limit(2) \
23
23
  .concat([4]) \
@@ -52,7 +52,7 @@ assert Opt(None).absent
52
52
 
53
53
  Map *optional*:
54
54
  ```python
55
- assert Opt("String").map(len).get() == 6
55
+ assert Opt("String").map(str.lower).len == 6
56
56
  ```
57
57
 
58
58
  Get default value:
@@ -146,7 +146,7 @@ list = [
146
146
  {"node": Node(name="Node C")},
147
147
  {"node": Node(name="Node D")},
148
148
  ]
149
- Stream(list).map_keys("node", "name")
149
+ names = Stream(list).map_keys("node", "name")
150
150
  ```
151
151
 
152
152
  ### Collected join
@@ -155,6 +155,16 @@ Stream(list).map_keys("node", "name")
155
155
  all_names = Stream([child]).map_key("name").join(", ")
156
156
  ```
157
157
 
158
+ ### Map kwargs
159
+ ```python
160
+ list = [
161
+ {"name": "Node A"},
162
+ {"name": "Node B"},
163
+ ]
164
+ # Short cut for map(lambda x: Node(**x))
165
+ nodes = Stream(list).map_kwargs(Node)
166
+ ```
167
+
158
168
  ### Stream many
159
169
 
160
170
  ```python
@@ -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.11",
13
+ version="0.1.13",
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.11
3
+ Version: 0.1.13
4
4
  Summary: Yet another python streams library
5
5
  Home-page: https://github.com/mreiche/python-streams
6
6
  Author: Mike Reiche
@@ -24,9 +24,9 @@ from tinystream import Stream
24
24
  stream = Stream([1, 2, 3, 4, 5]) # Stream.of_many(*), Stream.of_dict()
25
25
 
26
26
  stream \
27
- .map(lambda x: x + 1) \ # flatmap(), peek(), map_key()
27
+ .map(lambda x: x + 1) \ # flatmap(), peek(), map_key(), map_kwargs(), map_keys()
28
28
  .filter(lambda x: x > 2) \ # filter_key(), filter_type()
29
- .sorted(int, reverse=True) \ # sort()
29
+ .sorted(reverse=True) \ # sort()
30
30
  .reverse() \
31
31
  .limit(2) \
32
32
  .concat([4]) \
@@ -61,7 +61,7 @@ assert Opt(None).absent
61
61
 
62
62
  Map *optional*:
63
63
  ```python
64
- assert Opt("String").map(len).get() == 6
64
+ assert Opt("String").map(str.lower).len == 6
65
65
  ```
66
66
 
67
67
  Get default value:
@@ -155,7 +155,7 @@ list = [
155
155
  {"node": Node(name="Node C")},
156
156
  {"node": Node(name="Node D")},
157
157
  ]
158
- Stream(list).map_keys("node", "name")
158
+ names = Stream(list).map_keys("node", "name")
159
159
  ```
160
160
 
161
161
  ### Collected join
@@ -164,6 +164,16 @@ Stream(list).map_keys("node", "name")
164
164
  all_names = Stream([child]).map_key("name").join(", ")
165
165
  ```
166
166
 
167
+ ### Map kwargs
168
+ ```python
169
+ list = [
170
+ {"name": "Node A"},
171
+ {"name": "Node B"},
172
+ ]
173
+ # Short cut for map(lambda x: Node(**x))
174
+ nodes = Stream(list).map_kwargs(Node)
175
+ ```
176
+
167
177
  ### Stream many
168
178
 
169
179
  ```python
@@ -127,6 +127,13 @@ class Opt(Generic[T]):
127
127
  def stream(self):
128
128
  return Stream(self.__val)
129
129
 
130
+ @property
131
+ def len(self):
132
+ if self.absent:
133
+ return 0
134
+ else:
135
+ return len(self.__val)
136
+
130
137
 
131
138
  class EmptyOpt(Opt[None]):
132
139
  def __init__(self):
@@ -151,6 +158,10 @@ class EmptyOpt(Opt[None]):
151
158
  def stream(self):
152
159
  return Stream([])
153
160
 
161
+ @property
162
+ def len(self):
163
+ return 0
164
+
154
165
 
155
166
  class Stream(Iterator[T]):
156
167
 
@@ -207,6 +218,9 @@ class Stream(Iterator[T]):
207
218
  def map(self, mapper: Mapper[T, R]):
208
219
  return Stream[R](map(mapper, self))
209
220
 
221
+ def map_kwargs(self, mapper: Type[R]) -> "Stream[R]":
222
+ return self.map(lambda x: mapper(**x))
223
+
210
224
  def map_key(self, key: str | int):
211
225
  return self.filter_key(key).map(lambda x: _map_key(x, key))
212
226
 
@@ -253,7 +267,7 @@ class Stream(Iterator[T]):
253
267
  sort = sorted(self.__iterable, key=key, reverse=reverse)
254
268
  return Stream[T](sort)
255
269
 
256
- def sorted(self, key, reverse: bool = False):
270
+ def sorted(self, key: any = None, reverse: bool = False):
257
271
  sort = sorted(self.__iterable, key=key, reverse=reverse)
258
272
  return Stream[T](sort)
259
273
 
File without changes
File without changes