In the below method, if a certain condition is met, I'm using yield to return a generator. Within that same method, I'd like to check if the yield has already been triggered (thus the generator populated).
I've read that next(generator) is the common way to check if a generator is empty. But I don't see how I could apply that in this situation where the check has to happened within the method itself.
Here's the snippet :
def my_method(my_list: list) -> List[Iterable]:
for el in my_list:
if el == "foo":
yield el
if <yield_has_been_triggered> and el == "bar":
break
My current non-elegant solution is :
def my_method(my_list: list) -> List[Iterable]:
check = False
for el in my_list:
if el == "foo":
check = True
yield el
if check and el == "bar":
break
Is there a solution to get this <yield_has_been_triggered> information ?