I learned the intersperse function from Haskell, and have been looking for an implementation in c#.
Intersperse takes 2 arguments, an IEnumerable<T> source and a T element. It returns an IEnumerable with element inserted between every element of source.
One possible use-case is to put an arbitrary interger in between a list of integer...
Update: Here's a similar question
Suppose I have a DataTable with a few thousand DataRows in it.
I'd like to break up the table into chunks of smaller rows for processing.
I thought C#3's improved ability to work with data might help.
This is the skeleton I have so far:
DataTable Table = GetTonsOfData();
// Chunks should be any ...
Hi
I have this following IEnumerable LINQ query:
var query = from p in Enumerable.Range(2, 1000000)
let sumofPowers = from ch in p.ToString()
let sumOfPowers = Math.Pow(Convert.ToDouble(ch.ToString()), 5)
select sumOfPowers
where p == sumofPowers.Sum()
select p;
It finds the sum of all the numbers that can ...
I've noticed when writing LINQ-y code that .ForEach() is a nice idiom to use. For example, here is a piece of code that takes the following inputs, and produces these outputs:
{ "One" } => "One"
{ "One", "Two" } => "One, Two"
{ "One", "Two", "Three", "Four" } => "One, Two, Three and Four";
And the code:
private string InsertCommasAt...
In implementing a basic Scheme interpreter in C# I discovered, to my horror, the following problem:
IEnumerator doesn't have a clone method! (or more precisely, IEnumerable can't provide me with a "cloneable" enumerator).
What I'd like:
interface IEnumerator<T>
{
bool MoveNext();
T Current { get; }
void Reset();
// NEW...
I have two ListBoxes, lstAvailableColors and lstSelectedColors. Between each listbox are two buttons, Add and Remove. When a color or colors is selected in lstAvailableColors and the Add button is clicked, I want to remove them from lstAvailableColors and display them in lstSelectedColors. Also, if colors are selected in lstSelectedCo...
I'm currently trying to create a class which implements IEnumerable<T> in order to construct a Hierarchy from a flat list of objects which have references to each other through a ParentId property. I'd like to write a fluent interface for this so I can do something like this
IEnumerable<Tab> tabs = GetTabs();
IEnumerable<TabNode> tabNo...
In C# i have the following class and it compiles just fine:
class CustomItem
{
}
class CustomList : IList<CustomItem>
{
public CustomItem this[int index]
{
get { return null; }
set { throw new NotImplementedException(); }
}
public void CopyTo(CustomItem[] array, int arrayIndex)
{
}
...
I'm trying to build a way to get the key for a given piece of text in a given resx file at runtime.
Currently, I can open and read the file (Using ResXResourceReader) but I have to use a foreach to go over the entire file.
This could be a performance issue, as some of our resx files are fairly large (in the order of 2000 strings) and w...
Is it possible to return an IOrderedEnumerable<T> from a method without using the OrderBy or OrderByDescending methods on an IEnumerable<T>?
Im guessing perhaps not... but... maybe I am wrong?
Reason: Mostly curiosity. It just kind of hit me when making this answer on returning digits in a number. And my method would return the digit...
How do I make my Linq to Sql class IEnumerable or an object IEnumerable in C# 3.0
...
Hello all,
I am wondering if there is an easy and clean way (one line) to transform an enumeration of long (IEnumerable) to a single string (string) with LINQ?
Thanks
...
I could convert them to lists and just use a regular for loop with indexes, but I'm wondering if there's a way to do it that keeps them as IEnumerables.
...
So, I have a class with an array inside. Currently, my strategy for enumerating over the class's items is to use the code, foreach (item x in classInstance.InsideArray) . I would much rather use foreach (item x in classInstance) and make the array private. My main concern is that I really need to avoid anything slow; the array gets hi...
In C#, when writing a function that returns an IEnumerble<>, you can use yield return to return a single item of the enumeration and yield break; to signify no remaining items. What is the VB.NET syntax for doing the same thing?
An example from the NerdDinner code:
public IEnumerable<RuleViolation> GetRuleViolations() {
if (String...
I am having a hard time creating working Group By and Sort By clauses against a generic List myList.
myList has a list of property 'Settings' which itself contains a list of 'child' properties for each business.
I want to group by a Industry and within each Industry, sort by business name. My intent would be this:
string groupSetting...
Suppose I have an IEnumerable such as a List(TValue) and I want to keep track of whether this list is being accessed (to prevent issues with, say, adding to the list while it is being iterated over on a different thread); I can always write code such as the following:
Dim List1 As New List(Of Integer)
Dim IteratingList1 As Boolean = Fal...
Background: I have an ASP.NET MVC view page with a MultiSelectList in the View Model. I want to populate a label with the list of SelectedValues from that MultiSelectList object. The list is stored within the MultiSelectList with a type of IDName:
public class IDName {
public int ID {get; set;}
public string Name {get; set;}
}
...
For my function
public static IEnumerable<CallbackListRecord> LoadOpenListToProcess(CallbackSearchParams usp){}
This line errors when the sequence contains no elements (as it should)
CallbackListRecord nextRecord = CallbackSearch.LoadOpenListToProcess(p).First();
I have changed it to the following
CallbackListRecor...
So I have a collection of Razzies created from a Collection of Bloops. I retrieve this collection using a Linq query. Reference:http://stackoverflow.com/questions/923238/linq-select-certain-properties-into-another-object for the query.
I would like to know if it is possible to run a method on all of the newly created Razzies before re...