From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

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

Pipelining with extension methods

Pipelining with extension methods - C# Tutorial

From the course: Advanced C#: Functional Programming Patterns

Pipelining with extension methods

There's another functional composition pattern called pipelining. It's more popular than the previous example I showed you, and it's what's used in places in .NET like LINQ. In fact, I predict, if you were to talk to a C# developer or some .NET developers and talk about functional composition, they would think we're talking about pipelining, not the other example. The way we're going to implement this is using extension methods. I have them in this extensions class. And here's the key. We're making this an extension method. And the first parameter, in this case, is an int. To make pipelining work, the return type from this method also has to be an int. And you'll see that that's the case in all of my pipeline methods. Now the code itself is exactly the same code that we saw in the previous video. I have one called ToFourthPower, which is taking the number and multiplying it by itself four times. I have a MakeNegative and I have AddTo. So once we've created these, mark them as static…

Contents