Skip to content

Commit 372cc95

Browse files
author
czheo
committed
add pipe() | DEBUG
1 parent 8c7de24 commit 372cc95

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

syntax_sugar/pipe.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
__all__ = [
66
'END',
7+
'DEBUG',
78
'pipe',
89
'each',
910
'puts',
@@ -20,11 +21,17 @@ def puts(data, end="\n"):
2021
def each(fn):
2122
return partial(map, fn)
2223

23-
class end:
24+
class End:
2425
"mark end of pipe"
2526
pass
2627

27-
END = end()
28+
END = End()
29+
30+
class Debug:
31+
"mark end of pipe for debug"
32+
pass
33+
34+
DEBUG = Debug()
2835

2936
class MultiTask:
3037
def __init__(self, func):
@@ -92,9 +99,15 @@ def function(self, rhs):
9299
self.data = rhs(self.data)
93100

94101
def __or__(self, rhs):
95-
if isinstance(rhs, end):
102+
if rhs is END:
96103
# end of pipe
97104
return self.action(self.data)
105+
elif rhs is DEBUG:
106+
# debug end of pipe
107+
try:
108+
return self.action(self.data)
109+
except Exception as e:
110+
return e
98111
elif isinstance(rhs, list):
99112
if len(set(rhs)) != 1:
100113
raise SyntaxError('Bad pipe multiprocessing syntax.')

0 commit comments

Comments
 (0)