Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extension methods equivalents for CAR and CDR in .Net's Linq/IEnumerable

I know you can say SomeEnumerable.First(). But there's no .Rest.

I know I could write one, but I am wondering if I am missing something.

Related Question: Are there ruby equivalents to car, cdr, and cons?

like image 734
FastAl Avatar asked Feb 11 '23 18:02

FastAl


1 Answers

For CDR you can use Enumerable.Skip(1) like:

var cdrResultQuery = someIEnumerable.Skip(1);

Consider 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 will get:

2
3
4
5
like image 156
Habib Avatar answered Feb 15 '23 09:02

Habib