I'm studying about coroutines and I came across an explanation, about how yield as an expression, locks the function waiting to receive a value. Thinking about it, I ended up having an idea, which is the following: let's suppose that I wanted to make a filter in a querie (for example, using pandas). For this, I would make the query in the database before receiving the filter value, that is, the query would already be ready, just needing the filter. Think of the list as the result of the query:
def create_corroutine(func):
def wrapper(*args, **kwargs):
coro = func(*args, **kwargs)
next(coro)
return coro
return wrapper
@create_corroutine
def corroutine():
query = ['Giannis', 'Lebron', 'Ja Morant']
while True:
person_search = yield
person_search = [person for person in query if person == person_search]
print(person_search)
c = corroutine()
c.send('Lebron')
Is this a valid thought?