Lesson 11. Building composable functions
It seems strange to consider that we’re on lesson 11 and haven’t spent much time talking about functions! But you’ve already seen (and built your own) functions by now, so you’ve gained a little exposure to them. You can already do many of the same sorts of things you’d do with methods in C# or VB .NET. This lesson digs into how powerful functions in F# really are:
- You’ll gain a proper understanding of F# functions compared to methods.
- You’ll learn about a powerful technique called partial application.
- You’ll learn about two important operators in F# that help build larger pieces of code: pipeline and compose.
Have an energy drink before you start this lesson, as it’s probably the one lesson in this book that will throw the most at you in terms of F# features and syntax!
We tend to think of functions and methods as interchangeable terms. But let- bound functions in F# are an entirely different beast compared to methods. These are the sort of functions that you’ve already been defining so far—bound to a value through the let keyword (you can create classes with methods in F#, although I haven’t shown the syntax for this yet). Let’s see a quick comparison of methods and functions, as shown in table 11.1.