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
2 answers

PropertyChanged event doesn't work with collection created by yield

why does not working the following code? I have this class: public class ExportSetting : INotifyPropertyChanged { public Guid Guid { get; set; } public string Name { get; set; } private bool export; public bool Export { …
David
  • 17
  • 1
  • 6
0
votes
4 answers

Yield item in a list

In my application there is a List with a getter only: public List myList { get { MyHost.GetItemFromID(_i1); //this may be a long operation MyHost.GetItemFromID(_i2); MyHost.GetItemFromID(_i3); …
Sturm
  • 3,968
  • 10
  • 48
  • 78
0
votes
1 answer

Range with floating point numbers and negative steps

I wrote the following for creating a range with negative floating point steps: def myRange(start, stop, step): s = start if step < 0: while s > stop: yield s s += step if step > 0: while s < stop: …
vicco
  • 1,049
  • 2
  • 14
  • 33
0
votes
2 answers

How to write Scala recursion with for/yield?

I have the following list of pairs (key,id): val pairs = List(('a',1), ('a',2), ('b',1), ('b',2)) I need to generate all combinations of pairs when the keys are different so the expected output is: List( List(), List(('a', 1)), List(('a',…
Eran Witkon
  • 4,042
  • 4
  • 19
  • 20
0
votes
3 answers

Using "yield" in a function

I want to generate something like that in a function that receives 1 argument n using yield to generate: 1 1+2 1+2+3 … … 1+2+3+⋯+n−1+n That is my last try: def suite(n): total = 0 for i in n: total+=i …
Alex
  • 19
  • 2
0
votes
1 answer

Property access of yielded objects

I am trying to access the property of an object passed back using yield. function*test() { console.log(yield) console.log(yield(true).test) } var generator = test() generator.next({ test: true }) generator.next({ test: true }) generator.next({…
Daniel Herr
  • 19,083
  • 6
  • 44
  • 61
0
votes
2 answers

Python Recursive Generator

I'm trying to make a recursive generator, but I'm clearly missing something. Basically I have a list of positive and negative values for specific dimensions of a histogram, and want to get every combination of positive and negative. Ex: input =…
KevinShaffer
  • 760
  • 5
  • 14
  • 26
0
votes
0 answers

Removing for loops ladder in generator (yield), Python 2.7

Newbie here. Writing function that prints out all the subsets of a set using generator (yield statement). The problem is, I cannot make it so that it uses yield and works for sets of all lenghts, not only three, like in my code below. I can make it…
Victor
  • 31
  • 7
0
votes
3 answers

Turning any single-argument function into a generator function?

In David Beazley's talk on generators, he shows how to create a generator function from any single-argument function thus: def generate(func): def gen_func(s): for item in s: yield func(item) return gen_func and…
Pyderman
  • 14,809
  • 13
  • 61
  • 106
0
votes
2 answers

How to implement a complex process pipe in Python 2.6?

I like to have the Python (2.6, sorry!) equivalent of this shell pipe: $ longrunningprocess | sometextfilter | gzip -c That is, I have to call a binary longrunningprocess, filter its output through sometextfilter and need to get gzip output. I know…
user923543
0
votes
0 answers

return value from generator in py3.2 *and* py3.5

In Python 3.3 and newer, you can return a value from a generator; we use this in Tornado to have functions that call big and slow subprocesses (translate_part below) without blocking the main thread, and also without having more than one of the…
unhammer
  • 4,306
  • 2
  • 39
  • 52
0
votes
1 answer

Response yielded result in Tornado

I want to create messenger via websockets. My logic is: User_1 send a message (json) to User_2 via tornado handler, a message is checked (def send_message_to_RDB_parallel) on the tornado server (some requests to RDB, PostgreSQL) and then User_1…
Anton
  • 420
  • 5
  • 15
0
votes
1 answer

What is the best way to defer code execution?

I have many methods calling each other that each have to certain tasks, some of them asynchronous, that all operate on a DOM (so only one thread must access the DOM at any time). For example: object A() { /*...A() code 1...*/ var res = B(); …
manixrock
  • 2,533
  • 4
  • 24
  • 29
0
votes
1 answer

GetEnumerator: binding procedurally generated list to listbox with virtualization

I am trying to make an "infinite scrollable calendar". My idea is to generate the requested portion of the calendar on the fly, so as ItemsSource i use a custom class WeekList that implements IList. Upon initialization i calculate an interval around…
themightylc
  • 304
  • 2
  • 15
0
votes
1 answer

Laravel - @section to @Yield troubles blade

I have my master .php file setup here: views/layouts/app.blade.php and my child here views/tasks.blade.php In tasks.blade.php I wrote the following code: @extends('layouts.app') @section('content')
UserUser123
  • 145
  • 3
  • 8
1 2 3
99
100