-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexemplo_geradores_duno.py
More file actions
53 lines (36 loc) · 1.04 KB
/
exemplo_geradores_duno.py
File metadata and controls
53 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from corrotina import corrotina
@corrotina
def print_(formatação):
while True:
values = yield
print(formatação.format(*values))
@corrotina
def grep(target, pattern):
while True:
item = yield
if pattern in item:
target.send(item)
@corrotina
def replace(search, replace, *, target):
while True:
target.send(
(search, replace, (yield).replace(search, replace))
)
@corrotina
def dividir(*targets):
while True:
item = yield
for target in targets:
target.send(item)
printer = print_('Entrada: {} - Replace: {} - Valor final: {}')
replacer_spam = replace( # troca spam por bacon
search='spam', replace='bacon', target=printer
)
replacer_spam_spam = replace( # troca 'spam spam' por eggs
search='spam spam', replace='eggs', target=printer
)
branch = dividir(replacer_spam, replacer_spam_spam)
grepper = grep(branch, 'spam') # Filtra por spam
dados = ['spam', 'spam spam', 'eggs']
for line in dados:
grepper.send(line)