Skip to content

Commit 761be89

Browse files
committed
Singletonize getvalue, runpipe properly.
1 parent 9154dbe commit 761be89

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

unpythonic/seq.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,17 @@ def pipe1(value0, *bodys):
136136
x = update(x)
137137
return x
138138

139-
class getvalue: # sentinel with a nice repr
139+
getvalue = None
140+
class Getvalue: # singleton sentinel with a nice repr
140141
"""Sentinel; pipe into this to exit a shell-like pipe and return the current value."""
142+
def __new__(cls):
143+
global getvalue
144+
if getvalue is None:
145+
getvalue = super().__new__(cls)
146+
return getvalue
141147
def __repr__(self):
142148
return "<sentinel for pipe exit>"
143-
getvalue = getvalue() # singleton
149+
getvalue = Getvalue()
144150
runpipe = getvalue # same thing as getvalue, but semantically better name for lazy pipes
145151

146152
class piped1:

0 commit comments

Comments
 (0)