Today we are beginning a new topic, and it’s a really fun one. It has been nearly one year since Apple announced the Combine framework, which put a reactive framework in the hands of every single developer for Apple’s platforms. This was a huge announcement, because prior to this, adopting a reactive framework meant bringing in a library like RxSwift and ReactiveSwift. Some people thought those dependencies were too heavy to justify their utility, and others thought the reactive paradigm was too complicated and not worth the effort.
But now that Apple has handed down this framework, and it’s immediately available anytime you are building for Apple’s platforms, there isn’t as much to worry about as there used to be. Even if you do not want reactive code creeping into every part of your application, you can still make use of a bunch of APIs that have been improved using the reactive primitives. For example, there’s no reason to create a URLSession
data task from scratch, which you always have to remember to call .resume()
on it otherwise it won’t start. Instead you can use the publisher interface to that functionality, and things become quite simpler. Same goes for NSNotificationCenter
, which has a nice publisher interface that is much easier to use than the old API.
So, eventually more and more Combine code will be entering your code base, and we think that’s a good thing. It can really express some really powerful ideas in a small, succinct package. What’s not a good thing is that because Combine is so new it is lacking some crucial features. In particular, asynchronous reactive code is very difficult to test with Combine today. The abstractions are there to make this much nicer, but the actual implementations of those abstractions are still missing.
And we think this is an appropriate topic for us to cover on Point-Free because one of the big benefits to functional programming is testing. Typically functional code is very easy to test because you can just plug some data into a function and assert on what came out the other side. So, we’d hope that Combine code is also super testable, after all it is a functional reactive framework, but that sadly is not totally true right now.
So, we are going to fill that gap in the Combine framework, and along the way it is going to give us an excuse to dive deep into an advanced topic of Combine that hasn’t yet gotten much attention in the community.