Created
July 23, 2020 12:06
-
-
Save ayende/4db8a26020a58f921c244db38d4a29d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// map | |
from o in docs.Orders | |
from l in o.Lines | |
select new { | |
l.Product, | |
Related = o.Lines.Select(x=>x.Product) | |
.Where(x=>x!=l.Product) | |
.Select(x=>new { Count = 1, Product = x}), | |
Count = 1 | |
} | |
// reduce | |
from result in results | |
group result by result.Product into g | |
select new { | |
Product = g.Key, | |
Count = g.Sum(x=>x.Count), | |
Related = g.SelectMany(x=>x.Related) | |
.GroupBy(x=>x.Product) | |
.Select(x=>new { | |
Count = x.Sum(y=>y.Count), | |
Product = x.Key | |
}) | |
.OrderByDescending(x=>x.Count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment