Given the following query.
var query = files
.SelectMany(file => File.ReadAllLines(file))
.Where(_ => !_.StartsWith("*"))
.Select(line => new {
Order = line.Substring(32, 7),
Delta = line.Substring(40, 3),
Line = new String[] { line }
});
This clearly produces a list of objects with the properties Order: string
, Delta: string
and Line: string[]
I have a list of items that looks like this.
{ 1, 'A', {'line1'} },
{ 1, 'A', {'line2'} },
{ 2, 'B', {'line3'} },
{ 1, 'B', {'line4 } }
is it possible to use the Linq Aggregate
or similar functional construct to collect all the adjacent Order
and Delta
combinations together whilst accumulating the lines.
So that the aggregate is a list of items containing all it's 'lines'
{ 1, 'A', {'line1', 'line2'} }
{ 2, 'B', {'line3'} }
{ 1, 'B', {'line4'} }
Since aggregation iterates sequentially it should be possible to collect all the adjacent lines that have the same fields equal.
It's easy to do in a loop, but I am trying to do it with a set of lambdas.