We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 849d6ac commit 5985e7eCopy full SHA for 5985e7e
1 file changed
stream/parallelstream.py
@@ -0,0 +1,38 @@
1
+
2
+from stream import Stream
3
+from stream.iterators import IteratorUtils
4
5
6
+class ParallelUtils:
7
8
+ @staticmethod
9
+ def splitted(iterable, pre, offset):
10
+ for i in range(pre):
11
+ if next(iterable) is None:
12
+ return
13
+ while True:
14
+ elem = next(iterable)
15
+ if elem is None:
16
17
+ yield elem
18
+ for i in range(offset - 1):
19
20
21
22
23
+ def split(iterable, count):
24
+ iters = []
25
+ for i in range(count):
26
+ iters.append(ParallelUtils.splitted(iterable, i, count))
27
+ return iters
28
29
30
+class ParallelStream(Stream):
31
32
+ PROCESS = 4
33
34
+ def __init__(self, iterable):
35
+ self.__iterables = ParallelUtils.split(iterable, self.PROCESS)
36
37
+ def get(self):
38
+ return self.__iterables[0]
0 commit comments