I have a List<T>
and I want to obtain all possible sub lists, e.g.:
[A, B, C, D, E] => [[A], [A, B], [A, B, C], [A, B, C, D], [A, B, C, D, E]]
Is there an easy way to do obtain this new enumerable with LINQ to Objects?
EDIT 1: Note that I only want "prefix lists", not all possible permutations (i.e., the shown example result is already complete).
EDIT 2: Note that I want to maintain the order of the elements as well.
EDIT 3: Is there a way to obtain the enumerables in O(n) instead of O(n²), i.e., by iterating over the source only once instead of multiple times and returning some kind of view on the data instead of a new list each time?