Questions tagged [yield]

yield is (1) a keyword that facilitates creation of generator functions, (2) a Ruby statement to transfer control from one coroutine to another, (3) a Java statement used to yield a value from a switch expression.

In , the yield statement is only used when defining a generator function, and is only used in the body of the generator function. Using a yield statement in a function definition is sufficient to cause that definition to create a generator function instead of a normal function.

In , the yield statement is in context of coroutines generally used to transfer control from one coroutine to another, for example from a method to a block passed into it as an argument.

’s yield return is equivalent to Python’s yield, and yield break is just return in Python. In C#, yield is used in an iterator block to provide a value to the enumerator object or to signal the end of iteration.

yield is used in and generator functions in the same way it is in Python generator functions.

In yield is used in for-comprehension construction. for-comprehension iterates over one or more collections and uses yield to create and return new collection.

In , yield is a keyword used in a statement yield: <yield-target> to yield a value, which becomes the value of the enclosing switch expression.

1730 questions
0
votes
0 answers

python dictionary 'stickiness' when iterating through generators

I have a generator function (generate_email_activity()) which is iterated through within a second function (to_amplitude()). The generator function yields a dictionary. In my loop which iterates through the generator I have a problem: I apply…
Alexander Soare
  • 2,825
  • 3
  • 25
  • 53
0
votes
0 answers

R YieldCurve Nelson Siegel fitting

I have been able to get Nelson-Siegel parameters but I would like to use those parameters to fit multiple daily maturities in xts object. My example parameter data looks like: beta_0 beta_1 beta_2 lambda 2016-05-09 1.242251…
Hakki
  • 1,440
  • 12
  • 26
0
votes
1 answer

Scrapy item yields repeat values

I would appreciate a nudge in the right direction with this problem. Below is a spider that: 1. crawls listing page and retrieves each record's summary info (10 rows/page) 2. follows the URL for to extract detailed info on each individual record's…
user1330734
  • 390
  • 6
  • 21
0
votes
2 answers

How can I pass in a block to my "bubble sort" method?

The below code is my newbie take on a bubble sort method. #For each element in the list, look at that element and the element #directly to it's right. Swap these two elements so they are in #ascending order. def bubble_sort (array) a = 0 b…
d_zero
  • 21
  • 6
0
votes
2 answers

TypeError: object takes no parameters

I'm trying to create a code that utilizes the __iter__() method as a generator, but I am getting an error saying: TypeError: object() takes no parameters. Additionally, I am unsure whether my yield function should be called within try: or within…
D. Lopez
  • 3
  • 3
0
votes
1 answer

Returning paged results from WebMethod?

I need to create WebMethod that will get some data from db and return that to the client. Now, assume that the amount of data is huge, so I'd like to take and return data in parts. Is there any way to use yield return in Webmethod? As I know there…
iLemming
  • 34,477
  • 60
  • 195
  • 309
0
votes
4 answers

Rails yield - content_for problem

I have the following requirement. Ex: There is a transaction table where it has columns say, transaction_name and amount. I want to loop through the transactions and display their details (transaction_name and amount) and finally I want to display…
sameera207
  • 16,547
  • 19
  • 87
  • 152
0
votes
1 answer

unexpected error using yield in haml nesting

Server Log: Processing by GamesController#index as HTML Rendered games/index.haml within layouts/games (0.1ms) Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.0ms) Truncated layout is: %body = render partial:…
Vitalyp
  • 1,069
  • 1
  • 11
  • 20
0
votes
1 answer

Using yield with superagent returns request object instead of response

According to SuperAgent docs: SuperAgent docs var res = yield request .get('http://local') .auth('tobi', 'learnboost') However, I'm finding that the var res isn't res, its req. Meaning I have only access to the request object, not the response…
Tremendus Apps
  • 1,497
  • 12
  • 20
0
votes
1 answer

Rails "yield" not appearing on mobile devices

In my application.html.erb, I have a layout for my site:
Graham Slick
  • 6,692
  • 9
  • 51
  • 87
0
votes
0 answers

Is it possible to define custom genertors in Python?

The following code is transformed into a generator by the Python compiler: def myGenerator(max): for i in range(max): yield i It can be used with this code: >>> gen = myGenerator(10) >>> next(gen) 0 >>> next(gen) 1 If I query the class of…
Paebbels
  • 15,573
  • 13
  • 70
  • 139
0
votes
1 answer

Catching exception in decorator that wraps generator

I have a decorator that wraps a generator that yields from inside a nose test case. For every iteration, I'm looking to catch and run a specific teardown if an exception occurs, however it does not seem to behave as expected. def…
ILostMySpoon
  • 2,399
  • 2
  • 19
  • 25
0
votes
1 answer

how to use co with a named function?

So I am trying to use co to wrap around MongoDB methods that return promises eg http://mongodb.github.io/node-mongodb-native/2.0/reference/ecmascript6/crud/ I see co being used like: co(function*() { which seems like an anonymous function. Fine in…
dcsan
  • 11,333
  • 15
  • 77
  • 118
0
votes
2 answers

Unity C# Remember variables from before WaitForSeconds Yield

I'm trying to spawn a platform where the portal position was just at, so it looks like it's coming out of a portal. I'm having trouble with this line: Vector3 PlatformPosition = m_PortalPosition;, because SpawnPortal waits for 1 second and then…
Martin Dawson
  • 7,455
  • 6
  • 49
  • 92
0
votes
1 answer

Python Generator call counter not increasing unless yield is called

I am using the scandir library to look over all files on my computer. I would like to stop the loop once I've checked 100 records. If the yield statement is never called, my variable, c never increases and the loop doesn't stop. I've put in some…
user2242044
  • 8,803
  • 25
  • 97
  • 164
1 2 3
99
100