From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Compose functions

Compose functions

- It's time to look at how to use the functional compose pattern in C Sharp. If we were working in a functional language, that would be native sport in the language to do this, we don't have that in C Sharp, so we have to create a custom extension method, and that means our code will be less elegant. Before I show you the compose extension method, let's start by looking at the three functions we're going to use. They're simple mathematical functions, there's one on line 30, one on line 35, and one on here, on line 40. They all take on or more int parameters, and they produce an int as the output. So, this first one takes the inbound candidate, and multiplies it by itself four times, the second one turns that number into a negative value, and the last one takes two parameters, the candidate, and adds a number to that. They are simple, so we can show you how we would call these. In traditional imperative program we do…

Contents