// // FlowStateCombiner.swift // StoreFlowable // // Created by Kensuke Tamura on 2020/12/28. // public extension AsyncSequence { /** * Combine multiple `LoadingStateSequence`. * * - parameter statePublisher2: The second `LoadingStateSequence` to combine. * - parameter transform: This callback that returns the result of combining the data. * - returns: Return `LoadingStateSequence` containing the combined data. */ func combineState(_ statePublisher2: PUBLISHER_2, _ transform: @escaping (_ content1: RAW_CONTENT_1, _ content2: RAW_CONTENT_2) -> OUTPUT) -> LoadingStateSequence where Self.Element == LoadingState, PUBLISHER_2.Element == LoadingState { let combined = combineLatest(self, statePublisher2) return combined.map { (state1, state2) in state1.zip(state2, transform) }.eraseToLoadingStateSequence() } /** * Combine multiple `LoadingStateSequence`. * * - parameter statePublisher2: The second `LoadingStateSequence` to combine. * - parameter statePublisher3: The third `LoadingStateSequence` to combine. * - parameter transform: This callback that returns the result of combining the data. * - returns: Return `LoadingStateSequence` containing the combined data. */ func combineState(_ statePublisher2: PUBLISHER_2, _ statePublisher3: PUBLISHER_3, _ transform: @escaping (_ rawContent1: RAW_CONTENT_1, _ rawContent2: RAW_CONTENT_2, _ rawContent3: RAW_CONTENT_3) -> OUTPUT) -> LoadingStateSequence where Self.Element == LoadingState, PUBLISHER_2.Element == LoadingState, PUBLISHER_3.Element == LoadingState { combineState(statePublisher2) { (rawContent, other) in (rawContent, other) } .combineState(statePublisher3) { (rawContent, other) in transform(rawContent.0, rawContent.1, other) } } /** * Combine multiple `LoadingStateSequence`. * * - parameter statePublisher2: The second `LoadingStateSequence` to combine. * - parameter statePublisher3: The third `LoadingStateSequence` to combine. * - parameter statePublisher4: The fourth `LoadingStateSequence` to combine. * - parameter transform: This callback that returns the result of combining the data. * - returns: Return `LoadingStateSequence` containing the combined data. */ func combineState(_ statePublisher2: PUBLISHER_2, _ statePublisher3: PUBLISHER_3, _ statePublisher4: PUBLISHER_4, _ transform: @escaping (_ rawContent1: RAW_CONTENT_1, _ rawContent2: RAW_CONTENT_2, _ rawContent3: RAW_CONTENT_3, _ rawContent4: RAW_CONTENT_4) -> OUTPUT) -> LoadingStateSequence where Self.Element == LoadingState, PUBLISHER_2.Element == LoadingState, PUBLISHER_3.Element == LoadingState, PUBLISHER_4.Element == LoadingState { combineState(statePublisher2) { (rawContent, other) in (rawContent, other) } .combineState(statePublisher3) { (rawContent, other) in (rawContent.0, rawContent.1, other) } .combineState(statePublisher4) { (rawContent, other) in transform(rawContent.0, rawContent.1, rawContent.2, other) } } /** * Combine multiple `LoadingStateSequence`. * * - parameter statePublisher2: The second `LoadingStateSequence` to combine. * - parameter statePublisher3: The third `LoadingStateSequence` to combine. * - parameter statePublisher4: The fourth `LoadingStateSequence` to combine. * - parameter statePublisher5: The fifth `LoadingStateSequence` to combine. * - parameter transform: This callback that returns the result of combining the data. * - returns: Return `LoadingStateSequence` containing the combined data. */ func combineState(_ statePublisher2: PUBLISHER_2, _ statePublisher3: PUBLISHER_3, _ statePublisher4: PUBLISHER_4, _ statePublisher5: PUBLISHER_5, _ transform: @escaping (_ rawContent1: RAW_CONTENT_1, _ rawContent2: RAW_CONTENT_2, _ rawContent3: RAW_CONTENT_3, _ rawContent4: RAW_CONTENT_4, _ rawContent5: RAW_CONTENT_5) -> OUTPUT) -> LoadingStateSequence where Self.Element == LoadingState, PUBLISHER_2.Element == LoadingState, PUBLISHER_3.Element == LoadingState, PUBLISHER_4.Element == LoadingState, PUBLISHER_5.Element == LoadingState { combineState(statePublisher2) { (rawContent, other) in (rawContent, other) } .combineState(statePublisher3) { (rawContent, other) in (rawContent.0, rawContent.1, other) } .combineState(statePublisher4) { (rawContent, other) in (rawContent.0, rawContent.1, rawContent.2, other) } .combineState(statePublisher5) { (rawContent, other) in transform(rawContent.0, rawContent.1, rawContent.2, rawContent.3, other) } } }