score:8

Accepted answer

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.


Related Query

More Query from same tag