Top "Yield" questions

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.

Is it safe to combine 'with' and 'yield' in python?

It's a common idiom in python to use context manager to automatically close files: with open('filename') as my_file: # …

python yield with-statement
Trouble understanding yield in C#

I'm hoping to get some clarification on a snippet that I've recently stepped through in the debugger, but simply cannot …

c# .net yield yield-return
Use of yield with a dict comprehension

As a contrived example: myset = set(['a', 'b', 'c', 'd']) mydict = {item: (yield ''.join([item, 's'])) for item in …

python generator yield
Are there better ways to prevent 'yield' when no block is passed in?

I have a method that yields, which looks like: def a_method(*params) # do something yield # do something else end …

ruby block yield
Python: yield and yield assignment

How does this code, involving assignment and the yield operator, work? The results are rather confounding. def test1(x): for …

python yield assignment-operator
JS: how to use generator and yield in a callback

I use JS generator to yield a value in a callback of setTimeout: function* sleep() { // Using yield here is OK // …

javascript callback yield
yield return versus return select

Which are the advantages/drawbacks of both approaches? return items.Select(item => DoSomething(item)); versus foreach(var item in …

c# .net linq select yield
C# IEnumerator/yield structure potentially bad?

Background: I've got a bunch of strings that I'm getting from a database, and I want to return them. Traditionally, …

c# .net database resources yield
python try except yield combination

I use function f to create generator but sometimes it can raise error. I would like two things to happen …

python try-catch yield except