Let’s slow down and ask ourselves: what’s the point? Why are we doing all of this? In this episode we’ve introduced two custom operators and polluted the global namespace with free functions. Why not continue to use the methods we know and love?

Hopefully the code we’ve written today has made a strong case for introducing functions into our workflows: functions compose in ways that methods cannot. Composing functionality with methods requires a lot more work and boilerplate, and trying to see that composition afterwards requires filtering that noise. With just a couple operators, we unlock a world of composition that we didn’t have before, and we retain a lot of the readability we expect!

Swift also doesn’t really have a “global namespace” that we need to be worried about. We can scope our functions in a lot of different ways:

We can define functions that are private to a file.

We can define functions that are static members on structs and enums.

We can define functions that are scoped to modules. We can use several libraries that define the same function name, but qualify them by the library’s module name.

I think it’s safe to say: “Don’t fear the function.”

We’re going to be using functions a lot on Point-Free. It’s hard to imagine an episode in which we’re not going to be using free functions. We’ll be building very complex systems that under the hood are just functions and composition. It’s really beautiful and exciting to see how it all works and how everything pieces together. Function composition will continue to help us see things that we couldn’t have seen without it.

That’s enough for this episode, though. Stay tuned!