Oh sure. I was just discussing in the context of the example given in David Beazly's slides.
def grep(pattern):
print "Looking for %s" % pattern
while True:
line = (yield)
if pattern in line:
print line,
You initialize the coroutine with g = grep("python"). Isn't this step same as having a partial function with it's `pattern` argument with value "python"?
def grep(pattern, line):
if pattern in line:
print line,
And then:
g = partial(grep, pattern="python")
g(line='python in a line')
I'm sure this is a very simple example of coroutines, but if this is all I want to do (setting aside async vs sync for a moment), why would I use a coroutine here instead of a partial function?
EDIT: As I see more examples of coroutines especially the pipelining use cases, I was wrong and agree that it's completely different from partial functions.
I think I see where the confusion is coming from. A coroutine can be nexted repeatedly. A partial function can only be called once. The coroutine in the example is just a toy, so it's effectively the same as calling a partial many times in a loop. A more interesting coroutine might encapsulate state that changes across next'ing. Yes, other kinds of functions can change state across calls, too... It turns out many techniques can accomplish the same thing.
EDIT: As I see more examples of coroutines especially the pipelining use cases, I was wrong and agree that it's completely different from partial functions.