Search code examples
swiftuireactive-programmingnaming-conventionsnamingcombine

Etymology of "sink" in SwiftUI / Combine?


I'm joining development on an existing SwiftUI / Combine iOS project, which is my first exposure to the technology.

The names of functions like assign(to:on:) are easy enough to grok, but I'm lost at sink.

This function is mentioned in some of the most basic Apple documentation, but seemingly never defined.

Combine provides two built-in subscribers, which automatically match the output and failure types of their attached publisher:

  • sink(receiveCompletion:receiveValue:) takes two closures. The first closure executes when it receives Subscribers.Completion, which is an enumeration that indicates whether the publisher finished normally or failed with an error. The second closure executes when it receives an element from the publisher.

https://developer.apple.com/documentation/combine/receiving-and-handling-events-with-combine

What is a "sink" function in the the world of SwiftUI, Combine, reactive programming?

Why is it called "sink"? What's the etymology? What's the meaning?

Is it intended to refer to "sync" as in syncing? Kitchen sink? Heat sink? Going below the surface? Why is the name "sink"?


Solution

  • This same topic was discussed on the Swift forum:

    A brief rant on naming: Combine’s “sink” operator

    https://forums.swift.org/t/a-brief-rant-on-naming-combines-sink-operator/50076

    The replies make it clear that "source" and "sink" are established terms from graphy theory / flow networks.

    “Source” and “sink” are established names from graph theory. I agree that it’s not an everyday use of the word “sink”, though, or at least it’s a stretch.

    and

    In engineering generally, where there are flows (of anything: heat, data, water, etc.) the terms ‘source’ and ‘sink’ are commonly used to refer to locations where whatever is flowing (respectively) starts out / is produced and ends up / is consumed. So heat flows from its source toward a heat sink, water flows down a (kitchen?) sink, and Combine reactive streams flow toward a .sink(receiveValue:).