Equivalent extension methods for CAR and CDR in .Net Linq / IEnumerable

I know what you have to say SomeEnumerable.First()

. But there isn't .Rest

.

I know I can write one, but I'm wondering if I'm missing something.

Related question: Are there ruby ​​equivalents for car, cdr and cons?

+3


source to share


1 answer


For CDR

you can use Enumerable.Skip(1)

for example:

var cdrResultQuery = someIEnumerable.Skip(1);

      

Consider the following example:



IEnumerable<int> someIEnumerable = new List<int> {1, 2, 3, 4, 5};
var cdrResultQuery = someIEnumerable.Skip(1);
foreach (var i in cdrResultQuery)
{
    Console.WriteLine(i);
}

      

and you get:

2
3
4
5

      

+6


source







All Articles