Skip to content

Commit bfc8e21

Browse files
committed
Swap args of unpythonic.it.within() for curry-friendliness
1 parent 0a007d6 commit bfc8e21

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

unpythonic/it.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def windowed():
646646
xs.append(next(it)) # let StopIteration propagate
647647
return windowed()
648648

649-
def within(iterable, tol=0):
649+
def within(tol, iterable):
650650
"""Yield items from iterable until successive items are close enough.
651651
652652
Items are yielded until `abs(a - b) <= tol` for successive items

unpythonic/test/test_it.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ def g1():
235235
while True:
236236
yield x
237237
x /= 2
238-
assert tuple(within(g1(), 1/4)) == (1.0, 1/2, 1/4)
238+
assert tuple(within(1/4, g1())) == (1.0, 1/2, 1/4)
239239

240240
def g2():
241241
yield 1
242242
yield 2
243243
yield 3
244244
while True:
245245
yield 4
246-
assert tuple(within(g2(), 0)) == (1, 2, 3, 4, 4)
246+
assert tuple(within(0, g2())) == (1, 2, 3, 4, 4)
247247

248248
print("All tests PASSED")
249249

0 commit comments

Comments
 (0)