yield Questions
1
I'm not sure what the correct way is to early return in a function when using the yield keyword.
Is a "return void" return; the correct return value? Because the return type is specified to be ite...
12
Solved
I'm having a hard time wrapping my brain around PEP 380.
What are the situations where yield from is useful?
What is the classic use case?
Why is it compared to micro-threads?
So far I have used ...
5
Solved
I am currently in a personal learning project where I read in an XML database. I find myself writing functions that gather data and I'm not sure what would be a fast way to return them.
Which is g...
Brockway asked 15/8, 2010 at 14:34
5
Recently i have been using the 'yield' in python. And I find generator functions very useful. My query is that, is there something which could decrement the imaginative cursor in the generator obje...
10
Solved
I know there is no direct equivalent in Java itself, but perhaps a third party?
It is really convenient. Currently I'd like to implement an iterator that yields all nodes in a tree, which is about...
Kobe asked 30/12, 2009 at 16:8
20
Solved
In the How Can I Expose Only a Fragment of IList<> question one of the answers had the following code snippet:
IEnumerable<object> FilteredList()
{
foreach(object item in FullList)
{
i...
15
Solved
I heard about a "yield" keyword in JavaScript. What is it used for and how do I use it?
Disheveled asked 17/2, 2010 at 15:55
3
Solved
With ES6 generators, I see code like this:
var trivialGenerator = function *(array) {
var i,item;
for(var i=0; i < array.length; i++){
item = array[i];
yield item;
};
};
Is it possible to ...
Resilient asked 28/3, 2015 at 4:14
5
Solved
Is it possible, and if so, advisable, and if so, what would be the recommended method for decorating a function that yields a value?
For example, consider this imaginary example I made up
def foo...
Preventive asked 23/11, 2014 at 10:14
3
Solved
I'm trying to write a :rtype: type hint for a generator function. What is the type it returns?
For example, say I have this functions which yields strings:
def read_text_file(fn):
"""
Yields t...
Hackamore asked 27/4, 2017 at 13:15
4
Solved
I use JS generator to yield a value in a callback of setTimeout:
function* sleep() {
// Using yield here is OK
// yield 5;
setTimeout(function() {
// Using yield here will throw error
yield ...
Marquesan asked 26/12, 2016 at 3:41
4
Solved
After python 3.3.2+ python support a new syntax for create generator function
yield from <expression>
I have made a quick try for this by
>>> def g():
... yield from [1,2,3,4]
...
9
Solved
I have seen this syntax in MSDN: yield break, but I don't know what it does. Does anyone know?
3
Solved
I defined the function f as
def f(flag):
n = 10
if flag:
for i in range(n):
yield i
else:
return range(n)
But f returns a generator no matter what flag is:
>>> f(True)
<genera...
2
Solved
My understanding of yield from is that it is similar to yielding every item from an iterable. Yet, I observe the different behavior in the following example.
I have Class1
class Class1:
def __init...
Imogen asked 26/12, 2022 at 16:48
3
Solved
I'm currently trying to understand IEnumerator & Coroutine within the context of Unity and am not too confident on what the "yield return null" performs. At the moment i believe it basically pa...
Wicked asked 18/1, 2017 at 13:5
11
Solved
I understand Ruby and Python's yield. What does Scala's yield do?
Rakes asked 27/6, 2009 at 9:18
7
Solved
I need to write a simple script that loads data from multiple files and merges it somehow. However, given the fact that the files might be quite huge I'd like to load data partially. To do so I dec...
50
Solved
What functionality does the yield keyword in Python provide?
For example, I'm trying to understand this code1:
def _get_child_candidates(self, distance, min_dist, max_dist):
if self._leftchi...
18
Solved
I have a generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse the generator several times.
y = FunctionWit...
3
Solved
I stumble upon this code from pymotw.com in merging and splitting section.
from itertools import *
def make_iterables_to_chain():
yield [1, 2, 3]
yield ['a', 'b', 'c']
for i in chain....
Arquit asked 27/9, 2017 at 5:42
4
Solved
Edit: There is a similar question here that deals with iterator resetting. The accepted answer below however addresses the actual issue of nested iterators, and handles an easy to miss issue,...
27
Solved
I'm developing a console script for personal needs. I need to be able to pause for an extended amount of time, but, from my research, Node.js has no way to stop as required. It’s getting hard to re...
Pteridophyte asked 10/1, 2013 at 1:37
7
Solved
I had a code below in Python 3.2 and I wanted to run it in Python 2.7. I did convert it (have put the code of missing_elements in both versions) but I am not sure if that is the most efficient way ...
Prefix asked 10/7, 2013 at 21:37
2
Solved
I have a method that uses a background worker to poll a DLL for a status looking something like this:
var timeout = DateTime.Now.AddSeconds(3);
while (System.Status != Status.Complete // our statu...
Kleon asked 14/7, 2012 at 3:59
1 Next >
© 2022 - 2024 — McMap. All rights reserved.