Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public class Batch
  2. {
  3. public Guid Id { get; set; }
  4. public Item[] Items { get; set; }
  5. }
  6.  
  7. public class Item
  8. {
  9. public int Id { get; set; }
  10. public string Description { get; set; }
  11. }
  12.  
  13. Map = batches =>
  14. from batch in batches
  15. from item in batch.Items
  16. select new Result
  17. {
  18. Description = item.Description,
  19. ItemIds = new[] {item.Id}
  20. };
  21.  
  22. Reduce = results =>
  23. from result in results
  24. group result by result.Description into g
  25. select new Result
  26. {
  27. Description = g.Key,
  28. ItemIds = g.SelectMany(x => x.ItemIds).ToArray()
  29. };
  30.  
  31. Map = batches =>
  32. from batch in batches
  33. from item in batch.Items
  34. select new Result
  35. {
  36. Description = item.Description,
  37. ItemIdsAsString = item.Id.ToString(),
  38. };
  39.  
  40. Reduce = results =>
  41. from result in results
  42. group result by result.Description into g
  43. select new Result
  44. {
  45. Description = g.Key,
  46. ItemIdsAsString = string.Join("|", g.Select(x => x.ItemIdsAsString)),
  47. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement