업스트림 Publisher를 다른 타입의 퍼블리셔로 변환하는 Operator입니다.

특징

구성

public func flatMap<T, P>(
  maxPublishers: Subscribers.Demand = .unlimited,
  _ transform: @escaping (Self.Output) -> P
) -> Publishers.FlatMap<P, Self> where T == P.Output,
																			 P : Publisher,
																			 Self.Failure == P.Failure

파라미터에는 maxPublisher라는게 있어요.

maxPublisher로 최대로 동시에 가질 수 있는 Publisher의 수를 지정하거나 아니면 무제한으로 지정할 수 있어요. 기본값은 무제한이에요.

transform 클로저는 새로운 Publisher(Publishers.FlatMap)를 리턴해요.

Publishers.FlatMap의 제네릭 인자는 <NewPublisher, Upstream> 으로 구성되어 있어요.

따라서 flatMap 함수의 결과로 리턴되는 <P, Self> 는 곧 <P = NewPublisher, Self = Upstream> 이에요.

Publishers.FlatMap 의 receive(subscriber:) 부분을 볼게요.