-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuchen
committed
Jun 18, 2024
1 parent
ef6f140
commit b412395
Showing
4 changed files
with
341 additions
and
73 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,50 @@ | ||
from typing import List | ||
|
||
|
||
class CusotmerPiplineComponent: | ||
steps: List["CustomerRunnable"] | ||
|
||
def __init__(self, *steps): | ||
self.steps = steps | ||
|
||
def __or__(self, other: "CusotmerPiplineComponent"): | ||
return CusotmerPiplineComponent( | ||
*self.steps, other | ||
) | ||
|
||
def __ror__(self, other: "CusotmerPiplineComponent"): | ||
print(other) | ||
|
||
def __str__(self): | ||
return ",".join(map(lambda item: item.name, self.steps)) | ||
|
||
def invoke(self,**kwargs): | ||
print("kwargs:", kwargs) | ||
for item in self.steps: | ||
print(item.name) | ||
|
||
|
||
class CustomerRunnable: | ||
name: str | ||
|
||
def __init__(self, name: str): | ||
self.name = name | ||
|
||
def __or__(self, other: "CustomerRunnable"): | ||
# print(self.name,",",other.name) | ||
return CusotmerPiplineComponent( | ||
self, other | ||
) | ||
|
||
def __ror__(self, other: "CustomerRunnable"): | ||
if not other: | ||
return | ||
# print(self.name,"+",other.name) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
if __name__ == '__main__': | ||
res = CustomerRunnable("a") | CustomerRunnable("b") | CustomerRunnable("c") | ||
res.invoke(**{"input":12}) |
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
Oops, something went wrong.