From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Flatten with SelectMany

Flatten with SelectMany

The next concept we're looking at is called functional bind, but you'll find it goes by different names in various programming languages. In Haskell, it is called bind, while in Scala it's called flatMap. The concept itself is called flattening in C#, and it is implemented in LINQ with the SelectMany() method or the ContinueWith() method. In this video, we'll focus on the flattening aspect of bind using SelectMany(). Here's the problem that I have. I have this class called brand, and this represents the brands we work with in our ad agency. So the brand has the brand name and it has the brand colors and the brand socials that we're using for marketing. At some point, I'm going to create a list of brands, and then I want to be able to get the colors or the social values out of the list of brands. Now SelectMany in LINQ solves the problem of working with nested collections. That's what these are. These are nested lists that are inside the list of brands. LINQ solves the problem by…

Contents