Say I have the following code (context narrowed down as to keep the question scope limited)
public static IEnumerable<Color> GetThemColors(){
var ids = GetThePrimaryIds();
foreach (int id in ids){
yield return GetColorById(id);
}
ids = GetTheOtherIds();
foreach (int id in ids){
yield return GetOtherColorsById(id);
}
}
I woul...
So I was chatting with a colleague about fibers and turned up this paper from 2003 that describes a implementation of coroutines in C# using the Fiber API.
The implementation of Yield in this paper was for .NET 1.1, so it predates the yield return syntax that appeared in .NET 2.0.
It definitely looks, at first glance, that the impleme...
I am writing refactoring a Silverlight program to consumes a portion of its existing business logic from a WCF service. In doing so, I've run into the restriction in Silverlight 3 that only allows asynchronous calls to WCF services to avoid cases where long-running or non-responsive service calls block the UI thread (SL has an interestin...
I want to tell my Python threads to yield, and so avoid hogging the CPU unnecessarily. In Java, you could do that using the Thread.yield() function. I don't think there is something similar in Python, so I have been using time.sleep(t) where t = 0.00001. For t=0 there seems to be no effect.
I think that maybe there is something I am not...
I have the following code in django.template:
class Template(object):
def __init__(self, template_string, origin=None, name='<Unknown Template>'):
try:
template_string = smart_unicode(template_string)
except UnicodeDecodeError:
raise TemplateEncodingError("Templates can only be constructed fro...
Working through a tutorial (Professional ASP.NET MVC - Nerd Dinner), I came across this snippet of code:
public IEnumerable<RuleViolation> GetRuleViolations() {
if (String.IsNullOrEmpty(Title))
yield return new RuleViolation("Title required", "Title");
if (String.IsNullOrEmpty(Description))
yield return new RuleV...
I have a class and a set of IEnumerables that are using this class to give me a list in a list. (See this question's answer for details.)
Here is the code:
public IEnumerable<IEnumerable<WorkItemColumn>> EnumerateResultSet(WorkItemCollection queryResults)//DisplayFieldList displayFieldList)
{
foreach (WorkItem workItem in queryRes...
The code below works but I want to optimize the code using yield or by changing algorithm.
public IEnumerable<Book> GetAuthorWithBookName(string keyword)
{
var bookAndAuthorList = new List<Book>();
List<Author> AuthorNameList = getAuthorName(keyword);
foreach (var author in AuthorNameList)
{
XmlNode booksNames = ...
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 five lines of code with yield.
...
In Python, is there any difference between creating a generator object through a generator expression versus using the yield statement?
Using yield:
def Generator(x, y):
for i in xrange(x):
for j in xrange(y):
yield(i, j)
Using generator expression:
def Generator(x, y):
return ((i, j) for i in xrange(x) f...
I'm familiar with yeild to return a value thanks mostly to this question
but what does yield do when it is on the right side of an assignment?
@coroutine
def protocol(target=None):
while True:
c = (yield)
def coroutine(func):
def start(*args,**kwargs):
cr = func(*args,**kwargs)
cr.next()
return c...
Hi everybody,
I think this has been asked before but even though I searched Google I haven't come up with a solution.
So this is what I'm trying to do in Rails 2.3.5:
layouts/application.html.erb:
<html>
<head>
... some other stuff
<%= yield :head %>
</head>
<body>
<% content_for :head, "something that belongs in the...
I don't really understand how yield statement works in this situation. The problem says that given an expression without parentheses, write a function to generate all possible fully parenthesized (FP) expressions. Say, the input is '1+2+3+4' which should be generated to 5 FP expressions:
(1+(2+(3+4)))
(1+((2+3)+4))
((1+2)+(3+4))
((1+(2...
Hi everyone,
I have an IEnumerable<T> method that I'm using to find controls in a WebForms page.
The method is recursive and I'm having some problems returning the type I want when the yield return is returnig the value of the recursive call.
My code looks as follows:
public static IEnumerable<Control>
...
I need an extension method to traverse all Textboxes on my Silverlight page. Assume I always use a grid Layout, then I have:
public static IEnumerable<UIElement> Traverse(this UIElementCollection source, Func<Grid, UIElementCollection> fnRecurse)
{
foreach (UIElement item in source)
{
yield return item;
...
How might one implement C# yield return using Scala continuations? I'd like to be able to write Scala Iterators in the same style. A stab is in the comments on this Scala news post, but it doesn't work (tried using the Scala 2.8.0 beta). Answers in a related question suggest this is possible, but although I've been playing with delimited...
How can I yield multiple items at a time from an iterable object?
For example, with a sequence of arbitrary length, how can I iterate through the items in the sequence, in groups of X consecutive items per iteration?
(Question inspired by an answer which used this technique.)
...
Hello
Is there any way to have a yield created iterator continue to the next item when an exception occurs inside one of the iterator blocks?
This is currently not working:
Boolean result;
while (true)
{
try
{
result = enumerator.MoveNext(); //Taken from a yield created e...
I am trying to come up with an algorithm for a tree traversal, but I am getting stuck.
This is a fairly hard question (compared to others I have asked) so I may need to keep figuring on my own. But I thought I would throw it out here.
I have the following class structure:
public class Transition
{
// The state we are moving from....
I dont know the correct terminology for what i am asking
I tried to google it and couldnt ind anything for the same reason
I am writing a ruby library, and i want to rewite the functions so they work as below as i prefer it for readability (inside a block?)
at the moment i have a function that does this
@dwg = Dwg.new("test.dwg")
@dwg...