Learn Courses My Dashboard

What do angle brackets mean?

I’m working with PassthroughSubjects (whatever those are).

I’m guessing that you are dabbling in Combine.

Angle brackets < > usually indicate some kind of generic. The type(s) between the brackets are placeholder types in the definition and concrete types in the implementation.

So the definition

final class PassthroughSubject<Output, Failure> where Failure : Error

means that PassthroughSubject is a generic type that takes two placeholder types, referred to as Output and Failure (and it also indicates that Failure has to be a type of Error).

Whereas something like

var passthrough = PassthroughSubject<Int, Never>()

indicates that in this case the concrete type that replaces the Output placeholder is an Int and the concrete type for Failure is Never.

1 Like

Thank you!

What does "the concrete type for Failure is Never" mean?

I mean, I’d like my failure to be never, too.

It just means that that particular example of a PassthroughSubject will never fail; it will always produce a value of whatever type its Output is. This can be because the subject simply cannot fail (like, say if you use PassthroughSubject<Void, Never> because all you care about is the occurrence of an event rather than a particular value) or because any error was handled as part of the Combine pipeline and will never make it to the end, for instance by using the replaceError operator to ensure a valid value.

Sometimes PassthroughSubject or CurrentValueSubject can have a Failure type that is some specific type of Error, like PassthroughSubject<String, RegistrationError> or whatnot.