collections

Can I "pimp my library" with an analogue of TraversableLike.map that has nicely variant types?

Suppose I want to add functionality like map to a Scala List, something along the lines of list mapmap f, which applies the function f to each element of list twice. (A more serious example might be implementing a parallel or distributed map, but I don't want to get distracted by details in that direction.) My first approach would be o...

.NET collection to support LIFO

I need a .NET that supports last in first out (LIFO). Is there one? If there are more than one what is the best? (I plan to put Form objects in it.) Any suggestions? (NOTE: The collection needs to be on the Compact Framework. I am using Visual Studio 2008 and C#). ...

Questions with different types of answer in NHibernate

I'm trying to find a tidy solution to a questionnaire problem. Let us say that I have a Questionnaire class which has a collection of Answers, e.g. public class Questionnaire { public virtual ISet<Answer> Answers {get;set;} } Answers need to be of different types depending on the question, e.g. date of birth, marks out of ten, why...

Objective C collections, keeping uniques

In a collection how can I remove repetitions or preserve uniqueness? ...

Java collections: Compare elements in collection with each other and remove in one cycle

Say, I have a collection of some geolocations (in format Country > Region [ > Town [ > District]]) and I want to remove locations that overlap each other (for example, Europe > Germany overlaps Europe > Germany > Dresden and Europe > Germany > Hamburg, so the last two must be removed). I see that I need two instances of iterators to mak...

Strange C# struct in collection behaviour

Any ideas as to why this public Collection<Point> data = new Collection<Point>(){ new Point{X=10,Y=20}, new Point{X=20,Y=30}, new Point{X=40,Y=20}, new Point{X=10,Y=20} }; (notice the identical first and last elements) gives the error An item with the same key has alrea...

Finding duplicate objects in a collection using LINQ

Guys, I have a simple class representing an object. It has 5 properties (a date, 2 decimals, an integer and a string). I have a collection class, derived from CollectionBase, which is a container class for holding multiple objects from my first class. My question is, I want to remove duplicate objects (e.g. objects that have the same d...

NUnit Nested Collection Comparison

Is there something similar to CollectionAssert.AreEquivalent() that works with nested collections? The following code... CollectionAssert.AreEquivalent ( new Dictionary<int, Dictionary<int, string>> { { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary < i...

WPF refresh TreeView when it loses the focus

Hi! I have a problem with my TreeView in a WPF application (Framework 3.5 SP1). It's a TreeVIew with 2 Levels of Data. I expand / collapse the items of the first level in a particular way (with a single mouse-click on the TreeViewItem). Again when I expand a first-level TreeViewItem, I add some second-level TreeViewItems to the group (it...

collection_select doesn't let ActiveRecord update its collection when none of options is selected.

I have has_and_belongs_to_many association between two models. I made use of collection_select to represent the other model in this association in a form. When I tried to deselect options in collection_select, collection_select doesn't post its empty value and, thus, it doesn't let ActiveRecord pass any update clause to the database. ...

:limit number of rows found in a collect (has_many association)

Category has_many :products has_many :deals, :through => :products Product has_many :deals I want to display a limited number of deals on a category page. In categories_helper.rb: def deals @category.products.collect { |c| c.deals}.flatten end In the show.html.erb (Category): <% for deal in deals %> <%= deal.name %> <% en...

Dealing with collections with Parent -Child relationships in NHibernate

I'm having a problem with finding out which children to add, update and delete when I'm dealing with two lists one with the old chidren (from db) and the other list with the modified children (from user input). Currently I have to loop through the lists and compare to find the difference. Does anyone know of a better way of doing this...

Why is there a List<T>.BinarySearch(...)?

I'm looking at List and I see a BinarySearch method with a few overloads, and I can't help wondering if it makes sense at all to have a method like that in List? Why would I want to do a binary search unless the list was sorted? And if the list wasn't sorted, calling the method would just be a waste of CPU time. What's the point of havi...

Adding new object to generit List overwrites previous values

Hi guys, I have a problem with a generic list, which consists of intances of a class i created. I am just amazed, each time I add a new object to the list, it overwrites the previous entries. Here is a code sample, i just can't beleive it. I am using visual studio 2010: Dim translations As List(Of TranslatedValue) = New List(Of Transla...

How to bring an item to the top of ArrayList in java

I have an arraylist which I need to sort and also I need a specific default item to be on top of the list. I can do that myself checking the array list, delete the default item and insert it at the top of the list. Basically the list should be having a default value on top and remaining values in sorted order. Wants to know is there any...

Declarative syntax for a collection of value types in ASP.NET?

I know that in ASP.NET (talking about 2.0 here primarily) one can set a property on an object that takes a collection of things (an enumerable type I'm guessing is the trigger) and then reference it declaritivly. For example: <ObjectDataSource properties="blahblahblah"> <SelectParameters> <asp:Parameter /> </SelectParam...

What is the best way to find all dependent children in a IEnumerable collection

I have a database with 2 tables: Items ItemDependencies Items has key of ID ItemDependencies have two columns: ItemId, and DependsOnItemId I conver this to a collection: IEnumerable<Item> items = GetItems(); each item has a: Dependencies property which is a List<Item> So i want to filter the initial items list to: Given a ...

How do I convert a recursive object to a Collection in C#?

I have a recursive object, a linked list really: public class LinkedList { public string UniqueKey { get; set; } public LinkedList LinkedList { get; set; } } LinkedList will have some object graph that will eventually end in LinkedList.LinkedList == null. I would like to take all the objects in the graph and put them into a ...

Element goes missing during iteration of Arraylist

Can somebody explain to me whats wrong with the below piece of code ? public static void main(String[] args) { List<String> l = new ArrayList<String>(); l.add("1"); l.add("2"); l.add("3"); l.add("4"); for (int i = 0; i < l.size(); i++) { if(l.get(i).equals("1")) l.remove(l.get(i)); else System.out.println(l.get...

How can I add " " to each item in this collection in RoR?

At the moment, I have this run of code: <%=h current_user.notes.collect { |t| t.name }.join(', ') %> which outputs this: note 1, note 2, note 3 How can I change it so that the output looks like this? "note 1", "note 2", "note 3" Thanks for reading. Edit: Here is the full code of KandadaBoggu's suggestion below $(window).ready(...