-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of passing a class as the function
- Loading branch information
1 parent
d02b1a7
commit 9731597
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Simple Lithops example using one single function invocation | ||
with a class as a function and a function as a parameter | ||
""" | ||
import lithops | ||
|
||
def mult(x, y): | ||
return x + y | ||
|
||
|
||
class MyClass: | ||
def __init__(self, base) -> None: | ||
self.base = base | ||
|
||
def __call__(self, x, fn) -> int: | ||
return fn(self.base, x) | ||
|
||
|
||
if __name__ == '__main__': | ||
fexec = lithops.FunctionExecutor() | ||
inst = MyClass(7) | ||
fexec.map(inst, [(8, mult), (6, mult)]) | ||
print(fexec.get_result()) |