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
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
:param fun: a generator
:param equals: test for equality
:param old: initiate form of data.
:returns: same generator with no repetitions
>>> norep = no_repetition()
@ -22,7 +23,7 @@ def no_repetition(equals=lambda x,y: x == y):
@wraps(fun)
def dont_repeat(*args, **kwrds):
gen = fun(*args, **kwrds)
old_s = ""
old_s = old
while True:
try:
new_s = next(gen)