Skip to content

Commit 1f429d3

Browse files
akbakb
authored andcommitted
Add mario.testing
1 parent b7ecdf6 commit 1f429d3

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/mario/testing/atools.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
async def async_drop_falsy(items):
2+
async for x in items:
3+
if x:
4+
yield x
5+
6+
7+
def drop_falsy(items):
8+
for x in items:
9+
if x:
10+
yield x
11+
12+
13+
def my_max(items):
14+
print("hello")
15+
16+
it = iter(items)
17+
18+
try:
19+
current_max = next(it)
20+
except StopIteration as e:
21+
raise ValueError("Iterable was empty") from e
22+
for x in it:
23+
24+
if x > current_max:
25+
current_max = x
26+
return x
27+
28+
29+
# def gen_max(items):
30+
# it = iter(items)
31+
# try:
32+
# current_max = next(it)
33+
# except StopIteration as e:
34+
# raise ValueError("Iterable was empty") from e
35+
# for x in it:
36+
37+
# if x > current_max:
38+
# current_max = x
39+
# yield x
40+
41+
42+
def gen_max(items):
43+
yield from [my_max(items)]
44+
45+
46+
import functools
47+
def wrap_sync_fold(function):
48+
@functools.wraps(function)
49+
def wrap(items):
50+
yield from [function(items)]
51+
52+
return wrap
53+
54+
55+
wrapped_max = wrap_sync_fold(my_max)
56+
57+
wrapped_drop_falsy = wrap_sync_fold(drop_falsy)

0 commit comments

Comments
 (0)