public static IObservable <Product> FindMostExpansivePurchase( IObservable <Order> ordersHistory, ProductsCatalog productsCatalog) { IObservable <Product> allOrdersProducts = ordersHistory.SelectMany(order => order.ProductsIds.Select(id => productsCatalog.FindById(id))); IObservable <long> maxProductPrice = allOrdersProducts.Max(price => price.Price); return(maxProductPrice.SelectMany(price => allOrdersProducts.Where(product => product.Price == price))); }
public IObservable <long> GetTotalPrice() => ProductsIds.ToObservable() .Select(id => _productsCatalog.FindById(id)) .Sum(product => product.Price);