add new setting for no_repetition decorator

This commit is contained in:
Benjamin Bertrand 2016-03-26 05:37:51 +03:00
parent 704d945bba
commit 0b3d162a8e

View File

@ -3,10 +3,11 @@
from functools import wraps from functools import wraps
def no_repetition(equals=lambda x,y: x == y): def no_repetition(equals=lambda x,y: x == y, old = ""):
""" Remove yield values which has already been yield """ Remove yield values which has already been yield
:param fun: a generator :param equals: test for equality
:param old: initiate form of data.
:returns: same generator with no repetitions :returns: same generator with no repetitions
>>> norep = no_repetition() >>> norep = no_repetition()
@ -22,7 +23,7 @@ def no_repetition(equals=lambda x,y: x == y):
@wraps(fun) @wraps(fun)
def dont_repeat(*args, **kwrds): def dont_repeat(*args, **kwrds):
gen = fun(*args, **kwrds) gen = fun(*args, **kwrds)
old_s = "" old_s = old
while True: while True:
try: try:
new_s = next(gen) new_s = next(gen)