5. What do we see
• It is imperative (repetitive, verbose etc.)
– Sort of awkward
• This is “default” way to iterate data structure
– Can be put into library
• But sometimes we want to iterate differently
– Determined by business rules
9. The problem
Given:
• Data structure knows how to iterate itself
• Additionally, we want to define other ways to
iterate data structure
Goal:
• Nice abstraction for that
38. Let’s recall our goal
Given:
• Data structure knows how to iterate itself
• Additionally, we want to define other ways to
iterate data structure
Goal:
• Nice abstraction for that
41. In fact, often we don’t need
iteration at all
Typical tasks:
• Find element(s) in sequence
• Check if condition is true/false for all elements
• Transform sequence
• Filter sequence
• Aggregate sequence
42. In these cases iteration is just an
implementation detail
We can express what we want declaratively
60. Sum up
• Use LINQ and LINQ extension methods
– to declaratively specify what you want
– to simplify your code
– to generalize your code
– to create complex abstractions from simple ones
• Remember that IEnumerables are lazy