Given the interface of IEnumerable<T>
, performance can not always be ensured.
You note that most functional programming languages implement tail and head. However it should be noted that these languages are acting on in memory constructs.
IEnumerable<T>
does not have any such constraints, and thus it cannot be assumed that this would be efficient.
A common functional pattern for example would be to recursively work on the Head of a collection and then recurse on the Tail of the call...
If you did this with Entity Framework for instance, you would send the following (meta) call to the SQL server, tight looped.
Select * from
(
Select * from
(
Select * from
(...)
Skip 1
)
Skip 1
);
Which would be highly inefficient.
EDIT:
Come to think about it. Another reason, is that C#/VB.Net doesn't support tail recursion, and thus, this pattern can easily cause a StackOverflow
.