In Scala there is a Stream class that is very much like an iterator. The topic Difference between Iterator and Stream in Scala? offers some insights into the similarities and differences between the two.
Seeing how to use a stream is pretty simple but I don't have very many common use-cases where I would use a stream instead of other a...
Is something like this possible?
Dim l As New List(Of T As Type Where GetType(BaseClass).IsAssignableFrom(T))
Note, my collection will be a collection of Types, not objects of type T - which I know is possible.
ETA:
The answers I've had so far are as expected - I didn't think it was possible.
What I'm trying to get my head round is...
I'm working with an external framework (redmine) which has one Project model that has_many EnabledModules.
Projects can have EnabledModules "attached" or "removed" via the module names, like this:
class Project < ActiveRecord::Base
...
has_many :enabled_modules, :dependent => :delete_all
...
def enabled_module_names=(module_nam...
I'm migrating a piece of code to make use of generics. One argument for doing so is that the for loop is much cleaner than keeping track of indexes, or using an explicit iterator.
In about half the cases, the list (an ArrayList) is being iterated in reverse order by using an index.
Can someone suggest a cleaner way of doing this (since...
Hello,
I have data that is a set of ordered ints
[0] = 12345
[1] = 12346
[2] = 12454
etc.
I need to check whether a value is in the collection in C++, what container will have the lowest complexity upon retrieval? In this case, the data does not grow after initiailization. In C# I would use a dictionary, in c++, I could either use a h...
One example of the general case:
public class Validator
{
// ...
public ReadOnlyCollection<InvalidContainer> ContainersUnderMinimum
{
get { return _containersUnderMinimum.AsReadOnly(); }
}
}
public class InvalidContainer
{
// ...
public int LowestVolume { get; set; }
}
The Validator class above takes a collect...
When I make a list box in WPF I frequently set its ItemsSource to be a List. Is there a Tree for TreeView (or what goes in ItemsSource for TreeView)?
Is there a collection or generally accepted method for handling tree data in C#.NET?
...
I have a view containing a ListView and an "Edit" Button. The ListView's ItemSource is bound to an ObservableCollection<Account> property on the underlying view model. Its SelectedItem property is also bound to the view model.
When the edit button is clicked, the existing view model launches an editing view/view model pair ("editing s...
OOC: Out Of Curiosity
So, as a little exercise and for the sake of learning, I decided to check if I was able to implement a very basic recursive function that would return a List<int>, but with the following restrictions:
1- The result should be returned by the function itself (as opposed to passed as an argument to a void function).
...
Question (in short):
I asked why .NET has IList<T>, which implements ICollection<T> and therefore provides methods to modify the list (Add, Remove, etc.), but doesn't offer any in-between interface such as IArray<T> to provide random access by index without any list modification.
EDIT 2010-Jan-21 2:22 PM EST:
In a comment to Jon Skeet...
Is it possible to allow duplicate values in the Set collection?
Is there any way to make the elements unique and have some copies of them?
Is there any functions for Set collection for having duplicate values in it?
...
Hi,
Is there any way to make a key for searching the values in the collections and not returning null keys and values?
...
Which is the most efficient way to traverse a collection?
List<Integer> a = new ArrayList<Integer>();
for (Integer integer : a) {
integer.toString();
}
or
List<Integer> a = new ArrayList<Integer>();
for (Iterator iterator = a.iterator(); iterator.hasNext();) {
Integer integer = (Integer) iterator.next();
integer.toString();...
I frequently expose typed collections and lists. Often when exposing collections and lists I am not happy with the Add and Remove methods being public. In older versions of .Net I have implemented IEnumerable but this is a lot of work.
What are the better alternatives?
I have seen questions similar to this, but not specifically about t...
Is there any collection class in java, that implements push_back() and push_front() methods?
...
I've got two List objects and I want to pair them up, just like the zip() function in Python. I'm pretty sure this isn't available in the JDK, but is there something like this in a fairly widespread library, similar to Apache Commons Collections? Thanks.
...
Hi,
I'm trying to have a (hash-based) Multimap with a (hash-based) Multiset of values for each key. See the example:
Multimap<Object, Object> mmap = Multimaps.newMultimap(
Maps.<Object, Collection<Object>>newHashMap(),
new Supplier<Collection<Object>>() {
public Collection<Object> get() {
return HashMultiset.create();
...
I have the following code:
IEqualityComparer<WorkItem> comparer =
new LambdaComparer<WorkItem>((item1, item2) => item1.Type == item2.Type);
var someVar = Pad.Distinct(comparer);
(The idea is to get 1 of each type)
And it is giving the following error message:
The type arguments for method 'System.Linq.Enumerable.Distinct
(Sy...
If have a class of Widgets like this:
public class Widget
{
public double Price { get; set; }
public string Type { get; set; }
public int ID { get; set; }
public string Name { get; set; }
}
And create a list of them:
List<Widget> Widgets = new List<Widget>
{
new Widget {ID = 1, Name = "One", Price = 3.00, Type =...
Hi, i have a question about how to do a common programming task in linq.
lets say we have do different collections or arrays. What i would like to do is match elements between arrays and if there is a match then do something with that element.
eg:
string[] collection1 = new string[] { "1", "7", "4" };
string[] collecti...