//I had a hard time coming up with something representative of complex business logic public IEnumerable<FooItem> ProcessFoos() { ItemRepository itemRepository = new ItemRepository(); IEnumerable<Item> items = itemRepository.GetAll(); //Processing the business logic is expensive Thread.Sleep(1000); return items.Where(item => item.IsFoo) .Select(item => new FooItem(item)); }
public void Run() { var repo = new ItemRepository(); var items = repo.GetAll(); var bars = items.Where(i => i.IsBar) .Select(i => new BarItem(i)); var logger = new ConsoleLogger(); foreach (var bar in bars) { //Deleting has a logging side effect logger.Log("Started deleting a record because of bar..."); //Deleting is expensive Thread.Sleep(10000); //Deleting has another logging side effect logger.Log("Deleted a record because of bar."); } }