> For the complete documentation index, see [llms.txt](https://presto95.gitbook.io/combine-rxswift-reactiveswift/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://presto95.gitbook.io/combine-rxswift-reactiveswift/publisher.md).

# Publisher

Publisher는 시간이 지남에 따라 값의 시퀀스를 전달할 수 있다.

Combine에서 `Publisher`는 프로토콜로 정의되어 있으며, 다음의 타입이 이 프로토콜을 채택한다.

* `Publishers` 열거형의 중첩 타입으로 정의된 여러 구조체
* `Just`, `Empty`와 같은 Convenience Publisher
* 타입을 지운 Publisher인 `AnyPublisher` 구조체
* 등등

두 개의 연관 타입이 정의되어 있다.

* 첫 번째 연관 타입은 값의 타입(`Output`)이다.
* 두 번째 연관 타입은 에러의 타입(`Failure`)이다.&#x20;
  * 에러의 타입은 `Error` 프로토콜을 채택해야 한다.

`Publisher` 프로토콜의 익스텐션으로 여러 오퍼레이터*operator*가 정의되어 있으며, 이를 사용해서 이벤트 처리 체인을 구성할 수 있다.

각 오퍼레이터는 `Publisher` 프로토콜을 구현하는 타입을 반환한다.

기본적으로 `Publisher` 프로토콜은 오퍼레이터의 이름과 그것이 반환하는 Publisher의 이름을 비슷하게 만들어 두었으나, 이 프로토콜을 채택하는 개별 Publisher는 오퍼레이터가 다른 타입의 Publisher를 반환하게 구현해둘 수 있다.

```swift
protocol Publisher { }

extension Publisher {
  func count() -> Publishers.Count<Self>
}

struct Just: Publisher {
  func count() -> Just<Int>
}
```

`Publisher` 프로토콜의 익스텐션으로 여러 오퍼레이터가 구현되어 있으나, `Just`와 같은 개별 Publisher가 오퍼레이터를 오버로딩하여 다른 타입을 반환하도록 구현한 경우를 어렵지 않게 찾아볼 수 있다.

## RxSwift

일반적으로 `Publisher` 프로토콜을 구현하는 타입은 RxSwift의 `Observable`과 비교 가능하다.

에러 연관 타입이 `Never`로 에러 값을 전달하지 않는다는 것이 보장되는 것은 RxCocoa의 `Driver`와 비교 가능하다.

하나의 값을 전달하고 종료하거나, 에러를 내고 종료하는 `Single`의 동작은 Combine의 `Future` Publisher를 사용하여 구현할 수 있다.

`Completable`, `Maybe`와 같은 RxSwift의 Traits는 Combine에 별도의 타입으로 구현되어 있지 않다.

## ReactiveSwift

일반적으로 `Publisher` 프로토콜을 구현하는 타입은 ReactiveSwift의 `SignalProducer`와 `Signal`과 비교 가능하다.

`SignalProducer`는 'Cold Observable', `Signal`은 'Hot Observable'을 의미하는데, Combine에서는 이 동작을 별도의 타입으로 구분하지 않는다.

## Publisher와 Operator 쌍

### Convenience Publishers

| Publisher                                                        | 관련 Operator |
| ---------------------------------------------------------------- | ----------- |
| [Future](/combine-rxswift-reactiveswift/publisher/future.md)     | -           |
| [Just](/combine-rxswift-reactiveswift/publisher/just.md)         | -           |
| [Deferred](/combine-rxswift-reactiveswift/publisher/deferred.md) | -           |
| [Empty](/combine-rxswift-reactiveswift/publisher/empty.md)       | -           |
| [Fail](/combine-rxswift-reactiveswift/publisher/fail.md)         | -           |
| Record                                                           | -           |

### Publisher in Publishers Enum

#### Convenience Publishers

| Publisher                                                        | 관련 Operator |
| ---------------------------------------------------------------- | ----------- |
| [Sequence](/combine-rxswift-reactiveswift/publisher/sequence.md) | -           |
| [Catch](/combine-rxswift-reactiveswift/publisher/catch.md)       | `catch`     |

#### Working with Subscribers

| Publisher                                                              | 관련 Operator |
| ---------------------------------------------------------------------- | ----------- |
| [ReceiveOn](/combine-rxswift-reactiveswift/publisher/receiveon.md)     | `receive`   |
| [SubscribeOn](/combine-rxswift-reactiveswift/publisher/subscribeon.md) | `subscribe` |

#### Mapping Elements

| Publisher                                                                    | 관련 Operator                                    |
| ---------------------------------------------------------------------------- | ---------------------------------------------- |
| [TryScan](/combine-rxswift-reactiveswift/publisher/tryscan.md)               | `tryScan`                                      |
| [TryMap](/combine-rxswift-reactiveswift/publisher/trymap.md)                 | `tryMap`                                       |
| FlatMap                                                                      | `flatMap`                                      |
| [Map](/combine-rxswift-reactiveswift/publisher/map.md)                       | `map` / `replaceNil` / `combineLatest` / `zip` |
| [MapError](/combine-rxswift-reactiveswift/publisher/maperror.md)             | `mapError`                                     |
| [Scan](/combine-rxswift-reactiveswift/publisher/scan.md)                     | `scan`                                         |
| [SetFailureType](/combine-rxswift-reactiveswift/publisher/setfailuretype.md) | `setFailureType`                               |

#### Filtering Elements

| Publisher                                                                              | 관련 Operator           |
| -------------------------------------------------------------------------------------- | --------------------- |
| [CompactMap](/combine-rxswift-reactiveswift/publisher/compactmap.md)                   | `compactMap`          |
| [Filter](/combine-rxswift-reactiveswift/publisher/filter.md)                           | `filter`              |
| [RemoveDuplicates](/combine-rxswift-reactiveswift/publisher/removeduplicates.md)       | `removeDuplicates`    |
| [ReplaceEmpty](/combine-rxswift-reactiveswift/publisher/replaceempty.md)               | `replaceEmpty`        |
| [ReplaceError](/combine-rxswift-reactiveswift/publisher/replaceerror.md)               | `replaceError`        |
| [TryCompactMap](/combine-rxswift-reactiveswift/publisher/trycompactmap.md)             | `tryCompactMap`       |
| [TryFilter](/combine-rxswift-reactiveswift/publisher/tryfilter.md)                     | `tryFilter`           |
| [TryRemoveDuplicates](/combine-rxswift-reactiveswift/publisher/tryremoveduplicates.md) | `tryRemoveDuplicates` |

#### Reducing Elements

| Publisher                                                                                                                                    | 관련 Operator    |
| -------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| [Collect](/combine-rxswift-reactiveswift/publisher/collect.md)                                                                               | `collect`      |
| [CollectByCount](/combine-rxswift-reactiveswift/publisher/collectbycount.md)                                                                 | `collect`      |
| [CollectByTime](/combine-rxswift-reactiveswift/publisher/collectbytime.md)                                                                   | `collect`      |
| [IgnoreOutput](/combine-rxswift-reactiveswift/publisher/ignoreoutput.md)                                                                     | `ignoreOutput` |
| [Reduce](https://github.com/presto95/Combine-RxSwift-ReactiveSwift/tree/a9a4a8aa03a4a3e56527cbbe7168b6c19ab16ebb/Publisher/Reduce/README.md) | `reduce`       |
| [TryReduce](/combine-rxswift-reactiveswift/publisher/tryreduce.md)                                                                           | `tryReduce`    |

#### Applying Mathematical Operations on Elements

| Publisher                                                                  | 관련 Operator         |
| -------------------------------------------------------------------------- | ------------------- |
| [Comparison](/combine-rxswift-reactiveswift/publisher/comparison.md)       | `max` / `min`       |
| [TryComparison](/combine-rxswift-reactiveswift/publisher/trycomparison.md) | `tryMax` / `tryMin` |
| [Count](/combine-rxswift-reactiveswift/publisher/count.md)                 | `count`             |

#### Applying Matching Criteria to Elements

| Publisher                                                                        | 관련 Operator     |
| -------------------------------------------------------------------------------- | --------------- |
| [TryAllSatisfy](/combine-rxswift-reactiveswift/publisher/tryallsatisfy.md)       | `tryAllSatisfy` |
| [AllSatisfy](/combine-rxswift-reactiveswift/publisher/allsatisfy.md)             | `allSatisfy`    |
| [Contains](/combine-rxswift-reactiveswift/publisher/contains.md)                 | `contains`      |
| [ContainsWhere](/combine-rxswift-reactiveswift/publisher/containswhere.md)       | `contains`      |
| [TryContainsWhere](/combine-rxswift-reactiveswift/publisher/trycontainswhere.md) | `tryContains`   |

#### Applying Sequence Operations to Elements

| Publisher                                                                                                                                             | 관련 Operator          |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| [FirstWhere](/combine-rxswift-reactiveswift/publisher/firstwhere.md)                                                                                  | `first`              |
| [LastWhere](/combine-rxswift-reactiveswift/publisher/lastwhere.md)                                                                                    | `last`               |
| [DropUntilOutput](/combine-rxswift-reactiveswift/publisher/dropuntiloutput.md)                                                                        | `drop`               |
| [DropWhile](/combine-rxswift-reactiveswift/publisher/dropwhile.md)                                                                                    | `drop`               |
| [TryDropWhile](/combine-rxswift-reactiveswift/publisher/trydropwhile.md)                                                                              | `tryDrop`            |
| [Concatenate](/combine-rxswift-reactiveswift/publisher/concatenate.md)                                                                                | `append` / `prepend` |
| [Drop](/combine-rxswift-reactiveswift/publisher/drop.md)                                                                                              | `dropFirst`          |
| [PrefixUntilOutput](/combine-rxswift-reactiveswift/publisher/prefixuntiloutput.md)                                                                    | `prefix`             |
| [PrefixWhile](/combine-rxswift-reactiveswift/publisher/prefixwhile.md)                                                                                | `prefix`             |
| [First](/combine-rxswift-reactiveswift/publisher/first.md)                                                                                            | `first`              |
| [Last](/combine-rxswift-reactiveswift/publisher/last.md)                                                                                              | `last`               |
| [TryFirstWhere](/combine-rxswift-reactiveswift/publisher/tryfirstwhere.md)                                                                            | `tryFirst`           |
| [TryLastWhere](/combine-rxswift-reactiveswift/publisher/trylastwhere.md)                                                                              | `tryLast`            |
| [TryPrefixWhile](https://github.com/presto95/Combine-RxSwift-ReactiveSwift/tree/a9a4a8aa03a4a3e56527cbbe7168b6c19ab16ebb/Publisher/TryPrefixWhere.md) | `tryPrefix`          |
| [Output](/combine-rxswift-reactiveswift/publisher/output.md)                                                                                          | `output`             |

#### Combining Elements from Multiple Publishers

| Publisher                                                                    | 관련 Operator     |
| ---------------------------------------------------------------------------- | --------------- |
| [CombineLatest](/combine-rxswift-reactiveswift/publisher/combinelatest.md)   | `combineLatest` |
| [CombineLatest3](/combine-rxswift-reactiveswift/publisher/combinelatest3.md) | `combineLatest` |
| [CombineLatest4](/combine-rxswift-reactiveswift/publisher/combinelatest4.md) | `combineLatest` |
| [Merge](/combine-rxswift-reactiveswift/publisher/merge.md)                   | `merge`         |
| [Merge3](/combine-rxswift-reactiveswift/publisher/merge3.md)                 | `merge`         |
| [Merge4](/combine-rxswift-reactiveswift/publisher/merge4.md)                 | `merge`         |
| [Merge5](/combine-rxswift-reactiveswift/publisher/merge5.md)                 | `merge`         |
| [Merge6](/combine-rxswift-reactiveswift/publisher/merge6.md)                 | `merge`         |
| [Merge7](/combine-rxswift-reactiveswift/publisher/merge7.md)                 | `merge`         |
| [Merge8](/combine-rxswift-reactiveswift/publisher/merge8.md)                 | `merge`         |
| [MergeMany](/combine-rxswift-reactiveswift/publisher/mergemany.md)           | `merge`         |
| [Zip](/combine-rxswift-reactiveswift/publisher/zip.md)                       | `zip`           |
| [Zip3](/combine-rxswift-reactiveswift/publisher/zip3.md)                     | `zip`           |
| [Zip4](/combine-rxswift-reactiveswift/publisher/zip4.md)                     | `zip`           |

#### Handling Errors

| Publisher                                                                      | 관련 Operator       |
| ------------------------------------------------------------------------------ | ----------------- |
| [AssertNoFailure](/combine-rxswift-reactiveswift/publisher/assertnofailure.md) | `assertNoFailure` |
| [Catch](/combine-rxswift-reactiveswift/publisher/catch.md)                     | `catch`           |
| [TryCatch](/combine-rxswift-reactiveswift/publisher/trycatch.md)               | `tryCatch`        |
| [Retry](/combine-rxswift-reactiveswift/publisher/retry.md)                     | `retry`           |

#### Adapting Publisher Types

| Publisher                                                                    | 관련 Operator      |
| ---------------------------------------------------------------------------- | ---------------- |
| [SwitchToLatest](/combine-rxswift-reactiveswift/publisher/switchtolatest.md) | `switchToLatest` |

#### Controlling Timing

| Publisher                                                                      | 관련 Operator       |
| ------------------------------------------------------------------------------ | ----------------- |
| [Debounce](/combine-rxswift-reactiveswift/publisher/debounce.md)               | `debounce`        |
| [Delay](/combine-rxswift-reactiveswift/publisher/delay.md)                     | `delay`           |
| [MeasureInterval](/combine-rxswift-reactiveswift/publisher/measureinterval.md) | `measureInterval` |
| [Throttle](/combine-rxswift-reactiveswift/publisher/throttle.md)               | `throttle`        |
| [Timeout](/combine-rxswift-reactiveswift/publisher/timeout.md)                 | `timeout`         |

#### Creating Reference-type Publishers

| Publisher | 관련 Operator |
| --------- | ----------- |
| Share     | `share`     |

#### Encoding and Decoding

| Publisher                                                    | 관련 Operator |
| ------------------------------------------------------------ | ----------- |
| [Encode](/combine-rxswift-reactiveswift/publisher/encode.md) | `encode`    |
| [Decode](/combine-rxswift-reactiveswift/publisher/decode.md) | `decode`    |

#### Identifying Properties with Key Paths

| Publisher                                                              | 관련 Operator |
| ---------------------------------------------------------------------- | ----------- |
| [MapKeyPath](/combine-rxswift-reactiveswift/publisher/mapkeypath.md)   | `map`       |
| [MapKeyPath2](/combine-rxswift-reactiveswift/publisher/mapkeypath2.md) | `map`       |
| [MapKeyPath3](/combine-rxswift-reactiveswift/publisher/mapkeypath3.md) | `map`       |

#### Using Explicit Publisher Connections

| Publisher   | 관련 Operator   |
| ----------- | ------------- |
| Autoconnect | `autoconnect` |

#### Working with Multiple Subscribers

| Publisher | 관련 Operator |
| --------- | ----------- |
| Multicast | `multicast` |

#### Buffering Elements

| Publisher | 관련 Operator |
| --------- | ----------- |
| Buffer    | `buffer`    |

#### Adding Explicit Connectability

| Publisher       | 관련 Operator       |
| --------------- | ----------------- |
| MakeConnectable | `makeConnectable` |

#### Debugging

| Publisher                                                                | 관련 Operator                        |
| ------------------------------------------------------------------------ | ---------------------------------- |
| [Breakpoint](/combine-rxswift-reactiveswift/publisher/breakpoint.md)     | `breakpoint` / `breakpointOnError` |
| [HandleEvents](/combine-rxswift-reactiveswift/publisher/handleevents.md) | `handleEvents`                     |
| [Print](/combine-rxswift-reactiveswift/publisher/print.md)               | `print`                            |

### Misc.

| Publisher                                                                                                | 관련 Operator           |
| -------------------------------------------------------------------------------------------------------- | --------------------- |
| [AnyPublisher](/combine-rxswift-reactiveswift/publisher/anypublisher.md)                                 | `eraseToAnyPublisher` |
| NotificationCenter.Publisher                                                                             | -                     |
| [Optional.Publisher](/combine-rxswift-reactiveswift/publisher/optional.publisher.md)                     | -                     |
| [Result.Publisher](/combine-rxswift-reactiveswift/publisher/result.publisher.md)                         | -                     |
| [URLSession.DataTaskPublisher](/combine-rxswift-reactiveswift/publisher/urlsession.datataskpublisher.md) | -                     |
| Timer.TimerPublisher                                                                                     | -                     |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://presto95.gitbook.io/combine-rxswift-reactiveswift/publisher.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
