[Vala] Is there a way to use the Vala coroutines to achieve the same effect as in the following Python snippet (coroutines returning partial results in an iterator-like way) ?
- From: Serge Hulne <serge hulne gmail com>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] Is there a way to use the Vala coroutines to achieve the same effect as in the following Python snippet (coroutines returning partial results in an iterator-like way) ?
- Date: Fri, 8 Jul 2011 14:43:46 +0200
Is there a way to use the Vala coroutines to achieve the same effect
as in the following Python snippet:
/////////////////////////////
################
# Python coroutine
###############*
def countdown(n):
print "Counting down from", n
while n > 0:
yield n
n -= 1
print "Done counting down"
# Example use
if __name__ == '__main__':
for i in countdown(10):
print i
///////////////////////////////
More precisely, is there a way to use a coroutine in order to achieve
an iterator-like effect, namely:
A regular routine would store the results in a data structure
(array,list ...) and return the whole bunch of results, all at once,
when the routine completes.
In the python example, above, partial results can be "returned" (or
rather transmitted using the yield keyword) as soon as they show up in
the coroutine.
- Can a similar effect be achieved in Vala using coroutines (or
something else) ?
Serge.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]