Transform callbacks into a stream
问题 In Perl, how can one transform a function that requires callbacks to a new function that returns a stream of results? Image I have a fixed function I can't change: sub my_fixed_handler { my $callback = shift; my $count = 1; while(1) { $callback->($count++); } } To print all the a count of numbers I could easily write this code: my_fixed_handler( sub { my $num = shift; print "...$num\n"; }); But now I need another function based on on the my_fixed_handler that will return only the result of