-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini-12.py
More file actions
42 lines (32 loc) · 764 Bytes
/
mini-12.py
File metadata and controls
42 lines (32 loc) · 764 Bytes
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
def coroutine(f):
def coroutine_next(*args, **kwargs):
coroutine_func = f(*args, **kwargs);
next(coroutine_func)
return coroutine_func
return coroutine_next
def storage():
values = set()
was_there = False
while True:
val = yield was_there
was_there = val in values
if not was_there:
values.add(val)
@coroutine
def cstorage():
values = set()
was_there = False
while True:
val = yield was_there
was_there = val in values
if not was_there:
values.add(val)
st = storage()
try:
print(st.send(42))
print(st.send(42))
except TypeError:
print("Here is error!")
cst = cstorage()
print(cst.send(42))
print(cst.send(42))