score:8
also, is there better name for the extension that might reflect that it is a well-known pattern (if, indeed it is a well-known pattern)?
yes - it is also known as pairwise
. it has been done before, for example here. there also has been a question about it before here on so.
pairwise can now be implemented in terms of zip for .net 4.0, as you point out. this seems like a reasonable approach for a linq to objects solution, although having a version that works on .net v3.5 too is probably more useful to a wider audience at this point.
score:3
when i did something similar, i called it selectwithprevious
and had a version that had overloads for both "selectwithpreviousitem" (took a func<tsource, tsource, tresult>
) and "selectwithpreviousresult" (took a func<tresult, tsource, tresult>
).
also, i implemented it by directly storing the last element rather than iterating the sequence twice like the zip approach does. having never used linq-to-sql, i can't say for sure, but i wonder if the zip/skip approach makes two trips to the server to evaluate a query twice.
Source: stackoverflow.com
Related Query
- How to Zip one IEnumerable with itself
- How to reinsert data from one table onto itself using LINQ in code migration?
- How to update Linq result with in the list, without assign other data table process itself get another one result
- How can I efficiently determine if an IEnumerable has more than one element?
- What does this C# code with an "arrow" mean and how is it called?
- linq how to select a parent with a child collection that contains one or many of an array (or list) of values
- How do I convert IEnumerable to Collection with linq
- How to Select All with a One to Many Relationship Using Linq
- How can I use linq to return integers in one array that do not match up with an integer property of another array?
- How to convert list of objects with two fields to array with one of them using LINQ
- How to properly integration test Web Api controller with IEnumerable results?
- How can I combine this code into one or two LINQ queries?
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- How to include one specific row from another table with LINQ to Entities
- linq - how do you do a query for items in one query source that are not in another one?
- How to Bind Exclude more than one property from a model with linq to sql asp.net mvc
- How to return rows with max value one column grouped by another column?
- How to handle IEnumerable with IGrouping in the view?
- How add multiple rows with one Insert query in EF
- How to query by where clause with EF code first
- How to get the value of class properties with Linq query and IEnumerable
- How to check an IEnumerable for multiple conditions with a single enumeration without buffering?
- How to find same classes in a list with one different value
- How to merge two lists that share 1 attribute into a third one with LINQ?
- How do I represent an option calculated column with EF Code First?
- How to perform Zip operation with null array
- How can I combine IObservable<T>.Throttle() with some other event source using Reactive Extensions?
- How can I select using LINQ for an entry that contains a LIST with more than one row?
- How to create a predicate that must meet two values with one being a list of values?
- How to use Where with IEnumerable assignment?
More Query from same tag
- This operation would create an incorrectly structured document
- Include coded field value in LINQ query (EF 5)
- Skip first column and get distinct from other columns
- Only parameterless constructors and initializers are supported in LINQ to Entities
- How to properly filter data using checkboxes?
- Can i have only one method to delete record from passed table name and id using Entity Framework and Linq?
- Linq converting implicitly to type
- Date range falling between two dates in a LINQ query
- ForEach extension method
- how to order a group result with Linq?
- How to get list of intermediate sums in a functional way? Using LINQ?
- sql to LINQ with left join group by and sum() throws exception
- Check the sum of a property of list items against another property
- updating multiple records in database with linq to sql without loop, is it possible?
- Using XDocument with namespaces
- Linq Sub Query is not working
- Grouping by anonymous v.s. grouping by non-anonymous
- LINQ and XDocument: How to create XML file?
- How to convert sql to LINQ combine LEFT JOIN, WHERE, GROUP BY and SUM in LINQ?
- Get id of new record in DNN Module
- how to Order a CollectionA using ListB ordering it in order of ListB Items in VB.net
- Custom compare dictionaries using LINQ
- C# Read and filter CSV file using LINQ
- Convert string value to entity in linq where query
- fastest way to compare if two ms sql tables are the same
- Finding an empty string in an array beginning at a specified index
- F# LINQ lastOrDefault unix Epoch
- How to convert this into a dictionary of a dictionary
- Can you use Linq to find relationships between elements in a collection?
- Grouping in Linq with TimeSpan.Hours