Return all enumerables with yield return at once; without looping through

I have the following function to get validation errors for a card. My question relates to dealing with GetErrors. Both methods have the same return type IEnumerable<ErrorInfo>. private static IEnumerable<ErrorInfo> GetErrors(Card card) { var errors = GetMoreErrors(card); foreach (var e in errors) yield return e; // further yield returns for more validation errors } Is … Read more

IEnumerable and Recursion using yield return

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> GetDeepControlsByType<T>(this Control control) { foreach(Control c … Read more

In practice, what are the main uses for the “yield from” syntax in Python 3.3?

I’m having a hard time wrapping my brain around PEP 380. What are the situations where yield from is useful? What is the classic use case? Why is it compared to micro-threads? So far I have used generators, but never really used coroutines (introduced by PEP-342). Despite some similarities, generators and coroutines are basically two … Read more

How can I wait In Node.js (JavaScript)? l need to pause for a period of time

I’m developing a console script for personal needs. I need to be able to pause for an extended amount of time, but, from my research, Node.js has no way to stop as required. It’s getting hard to read users’ information after a period of time… I’ve seen some code out there, but I believe they … Read more

What is the yield keyword used for in C#?

In the How Can I Expose Only a Fragment of IList<> question one of the answers had the following code snippet: IEnumerable<object> FilteredList() { foreach(object item in FullList) { if(IsItemInPartialList(item)) yield return item; } } What does the yield keyword do there? I’ve seen it referenced in a couple places, and one other question, but … Read more

What does the “yield” keyword do?

Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. without enough detail may be edited or deleted. What is the use of the yield keyword in Python? What does it do? For example, I’m trying to understand this code1: def _get_child_candidates(self, distance, … Read more