yield

Scala implementation of C#-like yield with "for"

I'm trying to use various scala implementations of C#-like yield return (i.e. link text) with "for" -constructions such as: private def permutations[T](s: Vector[T]) = { def swap(i: Int, j: Int) { val tmp = s(i) s.set(i, s.get(j)) s.set(j, tmp) } iterator[Vector[T]] { def generate(left: Int, right: Int): Unit @cps...

Scala collection: totally unpredictable behaviours...

Have been pretty frustrated by Scala 2.8 collection behaviours. Here's the problem: I'm creating a Sudoku board. I'm labelling the cells from A1 to I9 (the letters being the rows and the digits being the columns). I want to get a list of units on the board, which is the 9 rows, the night columns, and the night quadrants. Here's my scala...

C# - Serialization and the Yield statement

Is it possible to serialize a method containing yield statements (or a class that contains such a method) such that when you rehydrate the class, the internal state of the generated iterator is retained? ...

How does Rails yield to multiple block in the erb templates?

How does rails get away with the following in an .erb file? <%= yield :sidebar %> <%= yield :other_bar %> <%= yield :footer %> How are they able to yield multiple times in the same context to different symbols? Is this some kind of rails magic? I'm totally familiar with: def some_method(arg1, arg2, &block) yield(:block) end To m...

Stoping generator in first answer, use return instead

I am using too much to my taste the pattern (after every possible solution branch of the search). This is the code to find boggle words in given square. It had a bug if the words are not preselected to include only those whose letter pairs are neighbours, which I fixed now by changing comparrision not pos to pos is None. def word_path(w...

How do I break out of recursive IEnumerable<T> loops using yield break?

I have the following method that works well, except the yield break statement only breaks out of the current enumerator. I understand why this is the case, but I am drawing a blank over how to propogate the yield break up through the recursive stack. private static IEnumerable<Node> FindChildrenById(IEnumerable nodes, string parentT...

Events vs. Yield

I have a multithreaded application that spawns threads for several hardware instruments. Each thread is basically an infinite loop (for the lifetime of the application) that polls the hardware for new data, and activates an event (which passes the data) each time it collects something new. There is a single listener class that consolidat...

How does this function work in detail?

I got this method (inside a Unity C# Script), but I do not understand how the "yield" part actually works. I know from the MSDN that the function will return an IEnumerator which I could iterate throught, but this code waits 1,5 seconds and does not get iterated because this would mean, the objects created inside were created multiple t...

How to define a method some how like the 'yield' ( I mean, automatically catch the block)?

If I need to define a method called 'yields' which will call yiled 3 times: def yields 3.times do yield end end And then I will use it in an other method: def call_me_3_times yields end In the console or irb: >> call_me_3_times { puts 'me'} # => Cause error => LocalJumpError: no block given (yield) from (ir...

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(); /*...A() code 2 that uses res...*/ } object B() { /*...B code 1...*/ var re...

Which is generally faster, a yield or an append?

I am currently in a personal learning project where I read in an XML database. I find myself writing functions that gather data and I'm not sure what would be a fast way to return them. Which is generally faster: yields, or several append()s within the function then return the ensuing list? I would be happy to know in what situati...

F# yield! operator - Implementation and possible C# equivalents

I'm currently learning F# and I really love the yield! (yield-bang) operator. Not only for its name but also for what it does of course. The yield! operator basically allows you to yield all elements of a sequence from a sequence expression. This is useful for composing enumerators. Since I regularly encounter big, complicated enumerato...

Python yield returns characters instead of string from single-element tuple

I'm using yield to process each element of a list. However, if the tuple only has a single string element, yield returns the characters of the string, instead of the whole string: self.commands = ("command1") ... for command in self.commands: yield command # returns 'c' not 'command1' how can i fix this? Thanks ...

Can't bind to IEnumerable implementation using yield

I have a class encapsulating a bunch of collections. I would like to bind this class to a listbox to display the items in the collections. The class implements IEnumerable. When the listbox is displayed I am expecting the IEnumerable.GetEnumerator method to be called. It is however not when the GetEnumerator method uses the yield keyword...

appending to content_for in rails

We are currently in the process of refactoring our site and we have decided to just go with one js library (jquery). Problem is, due to time constraint, we can only do so much so at the moment, we have to make them coexist. This is easy since we have jquery's no conflict method, so I can just declare jquery then do the no conflict thing...

Alternative to IEnumerable<T>.Skip(1).Take(1).Single()

I am having a difficult time with a seemingly easy and embarrassing problem. All I want is the next element in an IEnumberable without using Skip(1).Take(1).Single(). This example illustrates the basic problem. private char _nextChar; private IEnumerable<char> getAlphabet() { yield return 'A'; yield return 'B'; yield retur...

How do I yield a pre-unpacked list?

I have a list that is created within an itertools.groupby operation: def yield_unpacked_list(): for key, grp in itertools.groupby(something_to_groupby, key=lambda x: x[0]): subset_of_grp = list(item[2] for item in list(grp)) yield key, subset_of_grp If, for example, subset_of_grp turns out to be [1, 2, 3, 4] and [5...

pthread scheduling problems.

I have two threads in a producer-consumer pattern. Code works, but then the consumer thread will get starved, and then the producer thread will get starved. When working, program outputs: Send Data...semValue = 1 Recv Data...semValue = 0 Send Data...semValue = 1 Recv Data...semValue = 0 Send Data...semValue = 1 Recv Data...semValue = 0...

Can we do Yield curves using Adobe Flex ?

I want to create Yield curves using adobe flex. pls, any one have an Idea how to create yield curves in a chart using flex... ...

yield iterator with reflection

I have a data class Student, and I have an aggregate class Students. Student has two properties of type string : Name and City. what I want to do is have the option to choose what property to iterate using the foreach mechanism. The code I wrote works and it's also readable and nice-looking. The main issue is performance : the line in...