Concept

Operators are functions in Combine that process or transform values emitted by a publisher before they reach the subscriber.

They sit between the publisher and the subscriber inside the Combine pipeline.

Conceptually:

Publisher → Operators → Subscriber

Operators allow developers to modify, filter, combine, or transform data streams.


Example Pipeline

let numbers = [1, 2, 2, 3, 4, 5].publisher

numbers
    .filter { $0 % 2 == 0 }
    .removeDuplicates()
    .map { $0 * 10 }
    .sink { value in
        print(value)
    }

This pipeline processes values step by step before delivering them to the subscriber.


Execution Flow

The publisher emits values:

1, 2, 2, 3, 4, 5

These values pass through each operator sequentially.


1. filter

.filter { $0 % 2 == 0 }

The filter operator allows only values that satisfy a condition to pass through the pipeline.

In this example, only even numbers pass.