Skip to content

Commit cb18218

Browse files
committed
Ensuring all of the examples work
1 parent 7f2e109 commit cb18218

File tree

2 files changed

+31
-36
lines changed

2 files changed

+31
-36
lines changed

README.md

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pipeline to do that like so:
7878
flowchart LR
7979
input[String]
8080
subgraph Pipeline
81-
pipe1[capitalize]
81+
pipe1[title]
8282
pipe2[trim]
8383
8484
pipe1 --> pipe2
@@ -90,14 +90,14 @@ flowchart LR
9090
```
9191

9292
```python
93-
from pypipeline import Pipeline
93+
from pypipeline.pipeline import Pipeline
9494

9595
# Create a new pipeline instance.
9696
pipeline = Pipeline()
9797

9898
# Send a string through the pipeline.
9999
result = pipeline.send(' hello world ').through([
100-
str.capitalize,
100+
str.title,
101101
str.strip
102102
]).then_return()
103103

@@ -112,7 +112,7 @@ You don't need to build the pipeline all at once, you can spread it out over a n
112112
flowchart LR
113113
input[String]
114114
subgraph Pipeline
115-
pipe1[capitalize]
115+
pipe1[title]
116116
pipe2[trim]
117117
pipe3[reverse_string]
118118
@@ -126,28 +126,25 @@ flowchart LR
126126
```
127127

128128
```python
129-
from pypipeline import Pipeline
129+
from pypipeline.pipeline import Pipeline
130130

131131
# Create a new pipeline instance.
132132
pipeline = Pipeline()
133133

134134
# Set the pipes you want to use.
135-
pipeline.through([
136-
str.capitalize,
137-
str.strip
138-
])
135+
pipeline.through([ str.title, str.strip ])
139136

140137
# Add another transformation.
141-
def reverse_string(s):
142-
return s[::-1]
138+
def replace(s):
139+
return s.replace('Hello', 'Goodbye')
143140

144141
# Add it to the pipeline.
145-
pipeline.pipe(reverse_string)
142+
pipeline.pipe(replace)
146143

147144
# Send data through the pipeline.
148145
result = pipeline.send(' hello world ').then_return()
149146

150-
print(result) # Output: 'dlrow olleh'
147+
print(result) # Output: 'Goodbye World'
151148
```
152149

153150
### Using custom pipes
@@ -172,21 +169,19 @@ flowchart LR
172169
```
173170

174171
```python
175-
from pypipeline import Pipeline
172+
from pypipeline.pipeline import Pipeline
176173

177174
pipeline = Pipeline()
178175

179176
def custom_pipe(passable, next_pipe):
180177
passable = passable.replace('hello', 'goodbye')
181178
return next_pipe(passable)
182179

183-
pipeline.through([
184-
custom_pipe,
185-
str.capitalize
186-
])
180+
pipeline.through([custom_pipe, str.title])
187181

188182
result = pipeline.send('hello world').then_return()
189183
print(result) # Output: 'Goodbye world'
184+
190185
```
191186

192187
### Using classes with the `handle` method
@@ -201,9 +196,9 @@ optionally implement the `StellarWP\Pipeline\Contracts\Pipe` interface to enforc
201196

202197
First class:
203198
```python
204-
class CapitalizePipe:
199+
class TitlePipe:
205200
def handle(self, passable, next_pipe):
206-
return next_pipe(passable.capitalize())
201+
return next_pipe(passable.title())
207202
```
208203

209204
Second class:
@@ -219,7 +214,7 @@ class StripPipe:
219214
flowchart LR
220215
input[String]
221216
subgraph Pipeline
222-
pipe1[CapitalizePipe::handle]
217+
pipe1[TitlePipe::handle]
223218
pipe2[StripPipe::handle]
224219
225220
pipe1 --> pipe2
@@ -231,9 +226,9 @@ flowchart LR
231226
```
232227

233228
```python
234-
from pypipeline import Pipeline
229+
from pypipeline.pipeline import Pipeline
235230

236-
pipeline = Pipeline().through([CapitalizePipe(), StripPipe()])
231+
pipeline = Pipeline().through([TitlePipe(), StripPipe()])
237232
result = pipeline.send(' hello world ').then_return()
238233
print(result) # Output: 'Hello world'
239234
```
@@ -247,9 +242,9 @@ the alternate method name using the `via()` method.
247242

248243
First class:
249244
```python
250-
class ReversePipe:
245+
class TitlePipe:
251246
def execute(self, passable, next_pipe):
252-
return next_pipe(passable[::-1])
247+
return next_pipe(passable.title())
253248
```
254249

255250
Second class:
@@ -277,11 +272,11 @@ flowchart LR
277272
```
278273

279274
```python
280-
from pypipeline import Pipeline
275+
from pypipeline.pipeline import Pipeline
281276

282277
pipeline = Pipeline().via('execute').through([StripPipe(), ReversePipe()])
283278
result = pipeline.send(' hello ').then_return()
284-
print(result) # Output: 'olleh'
279+
print(result) # Output: 'Hello'
285280

286281
```
287282

@@ -293,7 +288,7 @@ can do this with a `return` statement!
293288
#### Example pipeline
294289

295290
```python
296-
from pypipeline import Pipeline
291+
from pypipeline.pipeline import Pipeline
297292

298293
def check_content(passable, next_pipe):
299294
if 'stop' in passable:
@@ -331,7 +326,7 @@ flowchart LR
331326
```
332327

333328
```python
334-
from pypipeline import Pipeline
329+
from pypipeline.pipeline import Pipeline
335330

336331
pipeline = Pipeline().through([str.strip, str.upper])
337332
result = pipeline.send(' hello world ').then(lambda x: len(x))
@@ -358,7 +353,7 @@ pipeline.pipe( str.strip )
358353
# or
359354
pipeline.add_pipe( str.strip )
360355
# or
361-
pipeline.pipe( [ str.capitalize, str.strip ] )
356+
pipeline.pipe( [ str.title, str.strip ] )
362357
```
363358

364359
### `send()`
@@ -438,16 +433,16 @@ Aliases: `pipes()`
438433
#### Examples
439434
```python
440435
# You can provide any number of pipes.
441-
pipeline.through([ str.capitalize, str.strip ])
436+
pipeline.through([ str.title, str.strip ])
442437

443438
# Using the alias.
444-
pipeline.pipes([ str.capitalize, str.strip ])
439+
pipeline.pipes([ str.title, str.strip ])
445440

446441
# Pass closures as pipes.
447-
pipeline.through([ str.capitalize, lambda passable, next: next_pipe(passable.strip)])
442+
pipeline.through([ str.title, lambda passable, next: next_pipe(passable.strip)])
448443

449444
# Pass objects as pipes.
450-
pipeline.through([ CapitalizePipe(), StripPipe() ])
445+
pipeline.through([ TitlePipe(), StripPipe() ])
451446
```
452447

453448
### `via()`

pypipeline/pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def pipe(self, pipes: Union[List, Any]) -> 'Pipeline':
8585
Pipeline: Self
8686
"""
8787
if not isinstance(pipes, list):
88-
pipes = list(pipes)
88+
pipes = [pipes]
8989
self.pipes.extend(pipes)
9090
return self
9191

@@ -176,7 +176,7 @@ def through(self, pipes: Union[List, Any]) -> 'Pipeline':
176176
Returns:
177177
Pipeline: Self
178178
"""
179-
self.pipes = list(pipes) if isinstance(pipes, list) else list(pipes)
179+
self.pipes = list(pipes)
180180
return self
181181

182182
def via(self, method: str) -> 'Pipeline':

0 commit comments

Comments
 (0)