Combine Framework

Apple has presented Combine - a reactive stream library: https://developer.apple.com/documentation/combine

Thats a great addition - my questions might be:

  • Will this be part of the Core Libraries or Standard library?
  • Why didn't it go beyond what existing Rx libraries provide?

To the last point: We introduced the Result type so that we don't have to deal with 2 entry points (success and failure) in callbacks. Combine has separate entry points for success, failure and finished events. Why not consolidate this using the Result type?

Also, I would have hoped that Swifts version of Rx is more approachable - by using better namings. People new to reactive programming will be irritated by names like Subject, CurrentValueSubject. Maybe something like Signal and Property are more accessible to a broader audience.

2 Likes

This is an Apple framework written in Swift, but not part of the Swift project.

There already is an open source Swift version of Rx (https://github.com/ReactiveX/RxSwift). I guess combine is similar but does not follow the ReactiveX API.
For now, it is closed source and not cross-platform. Let's hope that Apple will open source it at some point and make it work on all Swift supported platforms.

A core and important difference is that Combine is based and built around the concepts of back-pressure (aka. flow-control) as established by https://www.reactive-streams.org (as Tony mentioned in Will SwiftNIO adapt to the new Combine framework?). It makes it somewhat of a "different beast" from an execution models perspective -- even if APIs seem quite similar.

I for one, am tremendously excited for the acknowledgement and solution (in Combine) of the need of asynchronous back-pressure in streaming -- it shows up in many many places after all :slight_smile:

2 Likes

+1 on this sentiment. I've always felt that the ReactiveX API is unnecessarily esoteric and this would be a good opportunity to iterate on it.

2 Likes

I haven't had a chance to look in to it in much detail yet, but broadly-speaking, I quite like the design of Combine.

I definitely think it is a good candidate for inclusion in the open-source project in some form (either as a corelib or as part of the standard library). There is nothing really magical about it - there are already plenty of reactive-stream libraries - but there would be a lot of value in standardising around a blessed library and common currency types.

It all depends if Apple is open to it or not (pun intended). Otherwise I suspect existing libraries like ReactiveX will continue to be preferred for cross-platform code with some kind of wrapper for when their streams end up in Apple-land. It would benefit all Swift code on all platforms if we could avoid that bifurcation.

We don't even need their implementation, just permission to use the API (since APIs are copyrightable).

2 Likes
Terms of Service

Privacy Policy

Cookie Policy