functionalthreading 0.2.2__tar.gz → 0.2.3__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.4
2
2
  Name: functionalthreading
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Functional programming with thread-based parallelism
5
5
  Author-email: Richard Tong <richytong@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/richytong/functionalthreading
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: functionalthreading
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Functional programming with thread-based parallelism
5
5
  Author-email: Richard Tong <richytong@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/richytong/functionalthreading
@@ -4,5 +4,4 @@ setup.py
4
4
  functionalthreading.egg-info/PKG-INFO
5
5
  functionalthreading.egg-info/SOURCES.txt
6
6
  functionalthreading.egg-info/dependency_links.txt
7
- functionalthreading.egg-info/top_level.txt
8
- functions/__init__.py
7
+ functionalthreading.egg-info/top_level.txt
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "functionalthreading"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  authors = [
5
5
  { name="Richard Tong", email="richytong@gmail.com" },
6
6
  ]
@@ -3,11 +3,10 @@ from tomllib import load
3
3
 
4
4
  with open('pyproject.toml', 'rb') as file:
5
5
  pyproject = load(file)
6
- print(pyproject)
7
6
 
8
7
  setup(
9
8
  name='functionalthreading',
10
9
  version=pyproject['project']['version'],
11
10
  description='Functional programming with thread-based parallelism',
12
- packages=['functions'],
11
+ packages=['src'],
13
12
  )
@@ -1,107 +0,0 @@
1
- from threading import Thread
2
- import itertools
3
-
4
- def _chain(argument, funcs):
5
- ret = argument
6
- for func in funcs:
7
- ret = func(ret)
8
- return ret
9
-
10
- def chain(argument, *funcs):
11
- """Chain functions together.
12
-
13
- Each function is evaluated in series starting from the first function, passing the return value as the first and only argument to the next function. The return value of the chain is the return value of the last function.
14
-
15
- ```python
16
- chain(
17
- 2,
18
- lambda n: n + 1,
19
- lambda n: n ** 2,
20
- lambda n: n / 3,
21
- print
22
- )
23
- ```
24
-
25
- If the first non-function argument is omitted, returns a function of chained functions that expects the non-function argument.
26
-
27
- ```python
28
- my_function_chain = chain(
29
- lambda n: n + 1,
30
- lambda n: n ** 2,
31
- lambda n: n / 3,
32
- print
33
- )
34
-
35
- my_function_chain(2)
36
- ```
37
-
38
- """
39
- if callable(argument):
40
- inner_funcs = (argument,) + funcs
41
- def inner_func(inner_argument):
42
- return _chain(inner_argument, inner_funcs)
43
- return inner_func
44
- return _chain(argument, funcs)
45
-
46
- def tap(func):
47
- """Call a function with an argument, returning the argument.
48
-
49
- ```python
50
- chain(
51
- 1,
52
- lambda n: n + 1,
53
- tap(print),
54
- lambda n: n + 2,
55
- tap(print),
56
- lambda n: n + 3,
57
- print
58
- )
59
- ```
60
-
61
- """
62
- def inner_func(argument):
63
- func(argument)
64
- return argument
65
- return inner_func
66
-
67
- class _Thread(Thread):
68
- def __init__(self, *args, **kwargs):
69
- Thread.__init__(self, *args, **kwargs)
70
- self.value = None
71
- self.target = kwargs['target']
72
- self.args = kwargs['args']
73
-
74
- def run(self):
75
- self.value = self.target(*self.args)
76
-
77
- def tmap(array_or_tuple, func):
78
- """Map a function concurrently across each element of an array or tuple.
79
-
80
- Each function invokation happens in a separate thread.
81
-
82
- ```python
83
- squared = tmap([1, 2, 3], lambda n: n ** 2)
84
- ```
85
-
86
- """
87
- length = len(array_or_tuple)
88
- threads = []
89
- index = 0
90
- args = [array_or_tuple]
91
- while index < length:
92
- t = _Thread(target=func, args=[array_or_tuple[index]])
93
- t.start()
94
- threads.append(t)
95
- index += 1
96
- index = 0
97
- result = []
98
- while index < length:
99
- t = threads[index]
100
- t.join()
101
- result.append(t.value)
102
- index += 1
103
- if isinstance(array_or_tuple, tuple):
104
- return tuple(result)
105
- return result
106
-
107
- __all__ = ['chain', 'tap', 'tmap']