using static MoreLinq.Extensions.GroupAdjacentExtension;
using static MoreLinq.Extensions.ScanRightExtension;
using static MoreLinq.Extensions.WindowRightExtension;
using static MoreLinq.Extensions.ForEachExtension;
StartDate = DateTime.Parse("2021-03-10"),
EndDate = DateTime.Parse("2021-03-21")
StartDate = DateTime.Parse("2021-03-10"),
EndDate = DateTime.Parse("2021-03-21")
StartDate = DateTime.Parse("2021-03-10"),
EndDate = DateTime.Parse("2021-03-23")
StartDate = DateTime.Parse("2021-03-10"),
EndDate = DateTime.Parse("2021-03-25")
.GroupAdjacent(x => x.EndDate)
.Select(xs => xs.Aggregate(
Ids = Enumerable.Empty<int>(),
StartDate = default(DateTime),
EndDate = default(DateTime)
Ids = acc.Ids.Append(curr.Id),
Quantity = acc.Quantity + curr.Quantity,
.Select(win => win.Count == 1
StartDate = win[0].EndDate.AddDays(1),
.ScanRight((curr, prev) => new {
Ids = curr.Ids.Concat(prev.Ids),
Quantity = curr.Quantity + prev.Quantity,
.Select(x => $"{{ Ids: [{string.Join(',', x.Ids)}], Quantity: {x.Quantity}, StartDate: {x.StartDate.ToShortDateString()}, EndDate: {x.EndDate.ToShortDateString()} }}")
.ForEach(x => Console.WriteLine(x));