yield Questions

2

import contextlib import time @contextlib.contextmanager def time_print(task_name): t = time.time() try: yield finally: print task_name, "took", time.time() - t, "seconds." def doproc(): x...
Unchartered asked 18/2, 2016 at 18:43

2

Solved

I am trying to create a custom data generator and don't know how integrate the yield function combined with an infinite loop inside the __getitem__ method. EDIT: After the answer I realized that t...
Denticulation asked 10/5, 2019 at 13:59

2

I am having a problem doing asynchronous stuff in the asyncio.Protocol.data_received callback of the new Python asyncio module. Consider the following server: class MathServer(asyncio.Protocol): ...
Leonor asked 23/12, 2013 at 15:37

4

Solved

Consider the following code: def mygen(): yield (yield 1) a = mygen() print(next(a)) print(next(a)) The output yields: 1 None What does the interpreter do at the "outside" yield exactly?
Rutherfurd asked 30/4, 2019 at 13:44

2

Solved

def foo(choice): for i in limit: d1 = doSomeCalc() d2 = doSomeOtherCalc() if choice == "stuff": yield { d1 : "value" } else: yield { d2 : "Othervalue" } I have a function that yields t...
Progeny asked 29/1, 2015 at 1:22

4

Solved

I have a method which takes a generator plus some additional parameters and returns a new generator: function merge(\Generator $carry, array $additional) { foreach ( $carry as $item ) { yield $i...
Kermes asked 21/8, 2014 at 14:12

4

Solved

Using PHP >= 5.5 if we have a method that yielded values, what would be the best method in counting these values? What I was expecting was to be able to convert a Generator to an array and count t...
Plossl asked 6/2, 2014 at 13:41

2

I don't see a very clear definition of the yield function in Kotlin. Example in the link above doesn't mention much but the following, val sequence = sequence { val start = 0 // yielding a sin...
Calderon asked 12/3, 2019 at 20:15

1

Solved

In the following code example: function* gen() { let v = yield Promise.resolve(0); return v; } The type of v is inferred to be any. I'm wondering if there's a way to get it to infer a differen...
Interjection asked 8/7, 2016 at 19:22

5

Solved

I have a function which yields results as it downloads them. For the purposes of this question, lets say I yield a sting once every second but I want a convenience function to wrap my generator: i...
Alligator asked 25/6, 2012 at 20:52

3

Solved

I want to know everything about the yield statement, in an easy to understand form. I have read about the yield statement and its ease when implementing the iterator pattern. However, most of it i...
Modulate asked 12/4, 2009 at 21:50

6

I have a for loop that checks a series of conditions. On each iteration, it should yield output for only one of the conditions. The final yield is a default, in case none of the conditions are true...
Whit asked 18/7, 2010 at 17:34

9

Solved

I am trying to do something to all the files under a given path. I don't want to collect all the file names beforehand then do something with them, so I tried this: import os import stat def expl...
Sang asked 20/7, 2011 at 0:59

4

In the following code: function so() { console.log('inside the timer') } function* sogen() { const callback = yield; setTimeout(callback, 2000); return 1; } function() { ...
Humic asked 16/10, 2018 at 22:10

5

Solved

I thought it would be nice to do something like this (with the lambda doing a yield return): public IList<T> Find<T>(Expression<Func<T, bool>> expression) where T : class, ...
Snuffle asked 1/8, 2009 at 23:10

5

Solved

I thought it would be nice to do something like this (with the lambda doing a yield return): public IList<T> Find<T>(Expression<Func<T, bool>> expression) where T : class, ...
Gaberdine asked 1/8, 2009 at 23:10

1

Solved

Is there any way to pass the last match (practically Regexp.last_match) to a block (iterator) in Ruby? Here is a sample method as a kind of wrapper of Srring#sub to demonstrate the problem. It acc...
Damon asked 16/9, 2018 at 23:39

1

Solved

I was messing around and noticed that the following code yields the value once, while I was expecting it to return a generator object. def f(): yield (yield 1) f().next() # returns 1 def g(): ...
Warhorse asked 9/9, 2018 at 18:37

2

The ES6 method: iterator.throw(err) is often described as injecting an exception as though it occurred at the yield statement in the generator. The problem is that the stack trace for this exceptio...
Moskow asked 17/5, 2015 at 18:29

4

Solved

When I use a generator in a for loop, it seems to "know", when there are no more elements yielded. Now, I have to use a generator WITHOUT a for loop, and use next() by hand, to get the next element...
Steinke asked 22/12, 2011 at 1:31

4

Solved

I have a Python generator that can call itself to get more elements to yield. It looks like this: def gen(list): # ... if list: for x in gen(list[1:]): yield x My question is about the last ...
Morley asked 6/6, 2011 at 20:28

1

Solved

In the following code, I have run into a RecursionError: maximum recursion depth exceeded. def unpack(given): for i in given: if hasattr(i, '__iter__'): yield from unpack(i) else: yield i so...
Seep asked 4/4, 2018 at 2:43

1

Solved

I have this code that makes a REST call: public IEnumerator GetCooroutine(string route) { string finalURL = URL + route; UnityWebRequest www = UnityWebRequest.Get(finalURL); yield return www.Se...
Gregoire asked 28/3, 2018 at 0:30

1

Solved

First of all, I'd like to mention that I am not particularly familiar with Python. I have recently been forced to familiarise myself with a code sample that's left my jaws ajar, and I have been una...
Sidneysidoma asked 3/3, 2018 at 5:46

4

The question "Meaning of the word yield" mentions the Enumerator::Yielder#yield method. I haven't used it before, and wonder under what circumstances it would be useful. Is it mainly useful when y...
Artema asked 21/2, 2011 at 22:6

© 2022 - 2024 — McMap. All rights reserved.