Skip to content

Commit 055c808

Browse files
committed
runpipe, getvalue -> exitpipe
Rename and deprecation (waiting until 0.15 to ax the old names). Getting rid of silly duplication by more descriptive naming.
1 parent 9e5f0a7 commit 055c808

4 files changed

Lines changed: 40 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ If you're still stuck on 3.4 and find something in the latest `unpythonic` 0.14.
5555

5656
- `setescape`/`escape` have been renamed `catch`/`throw`, to match the standard terminology in the Lisp family. **The old nonstandard names are now deprecated, and will be removed in 0.15.0.**
5757
- The parameters of `raisef` are now more pythonic, just the object `exc` and an optional keyword-only `cause`. **Old-style parameters are now deprecated, and will be removed in 0.15.0.** See [#30](https://github.com/Technologicat/unpythonic/issues/30).
58+
- `runpipe` and `getvalue` are now both replaced by a single unified name `exitpipe`. This is just a rename, with no functionality changes. **The old names are now deprecated, and will be removed in 0.15.0.**
5859
- The `dbg[]` macro now works in the REPL, too. See [#12](https://github.com/Technologicat/unpythonic/issues/12).
5960
- The `namedlambda` block macro now also names lambdas that are:
6061
- Passed as a named argument of a function call, as in ``foo(f=lambda ...: ...)``; or

doc/features.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -727,40 +727,42 @@ assert x == 85
727727

728728
We also provide ``pipec``, which curries the functions before applying them. Useful with passthrough (see below on ``curry``).
729729

730-
Optional **shell-like syntax**, with purely functional updates:
730+
Optional **shell-like syntax**, with purely functional updates.
731+
732+
*Changed in v0.14.2*. Both `getvalue` and `runpipe` are now known by the single unified name `exitpipe`. This is just a rename, with no functionality changes. The old names are now deprecated, and will be removed in 0.15.0.
731733

732734
```python
733-
from unpythonic import piped, getvalue
735+
from unpythonic import piped, exitpipe
734736

735-
x = piped(42) | double | inc | getvalue
737+
x = piped(42) | double | inc | exitpipe
736738
assert x == 85
737739

738740
p = piped(42) | double
739741
assert p | inc | getvalue == 85
740-
assert p | getvalue == 84 # p itself is never modified by the pipe system
742+
assert p | exitpipe == 84 # p itself is never modified by the pipe system
741743
```
742744

743745
Set up a pipe by calling ``piped`` for the initial value. Pipe into the sentinel ``getvalue`` to exit the pipe and return the current value.
744746

745-
**Lazy pipes**, useful for mutable initial values. To perform the planned computation, pipe into the sentinel ``runpipe``:
747+
**Lazy pipes**, useful for mutable initial values. To perform the planned computation, pipe into the sentinel ``exitpipe``:
746748

747749
```python
748-
from unpythonic import lazy_piped1, runpipe
750+
from unpythonic import lazy_piped1, exitpipe
749751

750752
lst = [1]
751753
def append_succ(l):
752754
l.append(l[-1] + 1)
753755
return l # this return value is handed to the next function in the pipe
754756
p = lazy_piped1(lst) | append_succ | append_succ # plan a computation
755757
assert lst == [1] # nothing done yet
756-
p | runpipe # run the computation
758+
p | exitpipe # run the computation
757759
assert lst == [1, 2, 3] # now the side effect has updated lst.
758760
```
759761

760762
Lazy pipe as an unfold:
761763

762764
```python
763-
from unpythonic import lazy_piped, runpipe
765+
from unpythonic import lazy_piped, exitpipe
764766

765767
fibos = []
766768
def nextfibo(a, b): # multiple arguments allowed
@@ -769,13 +771,13 @@ def nextfibo(a, b): # multiple arguments allowed
769771
p = lazy_piped(1, 1) # load initial state
770772
for _ in range(10): # set up pipeline
771773
p = p | nextfibo
772-
p | runpipe
774+
p | exitpipe
773775
assert fibos == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
774776
```
775777

776778
Both one-in-one-out (*1-to-1*) and n-in-m-out (*n-to-m*) pipes are provided. The 1-to-1 versions have names suffixed with ``1``. The use case is one-argument functions that return one value (which may also be a tuple).
777779

778-
In the n-to-m versions, when a function returns a tuple, it is unpacked to the argument list of the next function in the pipe. At ``getvalue`` or ``runpipe`` time, the tuple wrapper (if any) around the final result is discarded if it contains only one item. (This allows the n-to-m versions to work also with a single value, as long as it is not a tuple.) The main use case is computations that deal with multiple values, the number of which may also change during the computation (as long as there are as many "slots" on both sides of each individual connection).
780+
In the n-to-m versions, when a function returns a tuple, it is unpacked to the argument list of the next function in the pipe. At ``exitpipe`` time, the tuple wrapper (if any) around the final result is discarded if it contains only one item. (This allows the n-to-m versions to work also with a single value, as long as it is not a tuple.) The main use case is computations that deal with multiple values, the number of which may also change during the computation (as long as there are as many "slots" on both sides of each individual connection).
779781

780782

781783
## Batteries

unpythonic/seq.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
__all__ = ["begin", "begin0", "lazy_begin", "lazy_begin0",
55
"pipe1", "piped1", "lazy_piped1",
6-
"pipe", "piped", "getvalue", "lazy_piped", "runpipe",
6+
"pipe", "piped", "getvalue", "lazy_piped", "runpipe", "exitpipe",
77
"pipec", # w/ curry
88
"do", "do0", "assign"]
99

@@ -144,6 +144,10 @@ def __repr__(self):
144144
getvalue = Getvalue()
145145
runpipe = getvalue # same thing as getvalue, but semantically better name for lazy pipes
146146

147+
# New unified name for v0.15.0; deprecating the separate "getvalue" and "runpipe" as of v0.14.2.
148+
# TODO: Now that we have symbols, in v0.15.0, change this to `sym("exitpipe")` and delete the `Getvalue` class.
149+
exitpipe = getvalue
150+
147151
class piped1:
148152
"""Shell-like piping syntax.
149153
@@ -188,7 +192,7 @@ class lazy_piped1:
188192
the pipeline.
189193
190194
- ``lazy_piped`` just sets up a computation, and performs it when eventually
191-
piped into ``runpipe``. The computation always looks up the latest state
195+
piped into ``exitpipe``. The computation always looks up the latest state
192196
of the initial value.
193197
194198
Another way to say this is that ``lazy_piped`` looks up the initial value
@@ -204,7 +208,7 @@ def __init__(self, x, *, _funcs=None):
204208
def __or__(self, f):
205209
"""Pipe the value into f; but just plan to do so, don't perform it yet.
206210
207-
To run the stored computation, pipe into ``runpipe``.
211+
To run the stored computation, pipe into ``exitpipe``.
208212
209213
Examples::
210214
@@ -214,7 +218,7 @@ def append_succ(l):
214218
return l # important, handed to the next function in the pipe
215219
p = lazy_piped1(lst) | append_succ | append_succ # plan a computation
216220
assert lst == [1] # nothing done yet
217-
p | runpipe # run the computation
221+
p | exitpipe # run the computation
218222
assert lst == [1, 2, 3] # now the side effect has updated lst.
219223
220224
# lazy pipe as an unfold
@@ -226,10 +230,10 @@ def nextfibo(state):
226230
p = lazy_piped1((1, 1)) # load initial state into a lazy pipe
227231
for _ in range(10): # set up pipeline
228232
p = p | nextfibo
229-
p | runpipe
233+
p | exitpipe
230234
print(fibos)
231235
"""
232-
if f is runpipe: # compute now
236+
if f is exitpipe: # compute now
233237
v = self._x
234238
for g in self._funcs:
235239
v = g(v)
@@ -340,7 +344,7 @@ class lazy_piped:
340344
p3 = p2 | (lambda x, y, s: (x * 2, y + 1, "got {}".format(s)))
341345
p4 = p3 | (lambda x, y, s: (x + y, s))
342346
# nothing done yet!
343-
assert (p4 | runpipe) == (13, "got foo")
347+
assert (p4 | exitpipe) == (13, "got foo")
344348
345349
# lazy pipe as an unfold
346350
fibos = []
@@ -350,7 +354,7 @@ def nextfibo(a, b): # now two arguments
350354
p = lazy_piped(1, 1)
351355
for _ in range(10):
352356
p = p | nextfibo
353-
p | runpipe
357+
p | exitpipe
354358
print(fibos)
355359
"""
356360
def __init__(self, *xs, _funcs=None):
@@ -362,7 +366,7 @@ def __init__(self, *xs, _funcs=None):
362366
self._funcs = _funcs or ()
363367
def __or__(self, f):
364368
"""Pipe the values into f; but just plan to do so, don't perform it yet."""
365-
if f is runpipe: # compute now
369+
if f is exitpipe: # compute now
366370
vs = self._xs
367371
for g in self._funcs:
368372
if isinstance(vs, tuple):

unpythonic/test/test_seq.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from ..seq import begin, begin0, lazy_begin, lazy_begin0, \
44
pipe1, pipe, pipec, \
5-
piped1, piped, getvalue, \
6-
lazy_piped1, lazy_piped, runpipe, \
5+
piped1, piped, exitpipe, \
6+
lazy_piped1, lazy_piped, \
77
do, do0, assign
88

99
from ..ec import call_ec
@@ -69,11 +69,11 @@ def test():
6969
assert False # error if the curry context exits with args remaining
7070

7171
# optional shell-like syntax
72-
assert piped1(42) | double | inc | getvalue == 85
72+
assert piped1(42) | double | inc | exitpipe == 85
7373

7474
y = piped1(42) | double
75-
assert y | inc | getvalue == 85
76-
assert y | getvalue == 84 # y is never modified by the pipe system
75+
assert y | inc | exitpipe == 85
76+
assert y | exitpipe == 84 # y is never modified by the pipe system
7777

7878
# lazy pipe: compute later
7979
lst = [1]
@@ -82,7 +82,7 @@ def append_succ(l):
8282
return l # important, handed to the next function in the pipe
8383
p = lazy_piped1(lst) | append_succ | append_succ # plan a computation
8484
assert lst == [1] # nothing done yet
85-
p | runpipe # run the computation
85+
p | exitpipe # run the computation
8686
assert lst == [1, 2, 3] # now the side effect has updated lst.
8787

8888
# lazy pipe as an unfold
@@ -94,28 +94,28 @@ def nextfibo(state):
9494
p = lazy_piped1((1, 1)) # load initial state into a lazy pipe
9595
for _ in range(10): # set up pipeline
9696
p = p | nextfibo
97-
p | runpipe
97+
p | exitpipe
9898
assert fibos == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
9999

100100
# multi-arg version
101101
f = lambda x, y: (2 * x, y + 1)
102102
g = lambda x, y: (x + 1, 2 * y)
103-
x = piped(2, 3) | f | g | getvalue # --> (5, 8)
103+
x = piped(2, 3) | f | g | exitpipe # --> (5, 8)
104104
assert x == (5, 8)
105105

106106
# abuse multi-arg version for single-arg case
107-
assert piped(42) | double | inc | getvalue == 85
107+
assert piped(42) | double | inc | exitpipe == 85
108108

109109
# multi-arg lazy pipe
110110
p1 = lazy_piped(2, 3)
111111
p2 = p1 | (lambda x, y: (x + 1, 2 * y, "foo"))
112112
p3 = p2 | (lambda x, y, s: (x * 2, y + 1, "got {}".format(s)))
113113
p4 = p3 | (lambda x, y, s: (x + y, s))
114114
# nothing done yet, and all computations purely functional:
115-
assert (p1 | runpipe) == (2, 3)
116-
assert (p2 | runpipe) == (3, 6, "foo") # runs the chain up to p2
117-
assert (p3 | runpipe) == (6, 7, "got foo") # runs the chain up to p3
118-
assert (p4 | runpipe) == (13, "got foo")
115+
assert (p1 | exitpipe) == (2, 3)
116+
assert (p2 | exitpipe) == (3, 6, "foo") # runs the chain up to p2
117+
assert (p3 | exitpipe) == (6, 7, "got foo") # runs the chain up to p3
118+
assert (p4 | exitpipe) == (13, "got foo")
119119

120120
# multi-arg lazy pipe as an unfold
121121
fibos = []
@@ -125,7 +125,7 @@ def nextfibo(a, b): # now two arguments
125125
p = lazy_piped(1, 1)
126126
for _ in range(10):
127127
p = p | nextfibo
128-
p | runpipe
128+
p | exitpipe
129129
assert fibos == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
130130

131131
# do: improved begin() that can name intermediate results

0 commit comments

Comments
 (0)