Skip to content

Commit

Permalink
Remove unneeded spacing (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackstone92 authored Sep 20, 2024
1 parent ac46ad5 commit 3939763
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Combine
import RxSwift

extension Publisher where Failure == Never {

/// A bridging function that transforms a Combine `Publisher` into an RxSwift `Infallible`.
///
/// This is a direct transformation when the `Failure` type is already `Never`.
Expand All @@ -16,7 +15,6 @@ extension Publisher where Failure == Never {
///
public func asInfallible() -> Infallible<Output> {
return .create { observer -> Disposable in

let cancellable = sink(
receiveCompletion: { _ in observer(.completed) },
receiveValue: { observer(.next($0)) }
Expand All @@ -30,7 +28,6 @@ extension Publisher where Failure == Never {
}

extension Publisher {

/// A bridging function that transforms a Combine `Publisher` into an RxSwift `Infallible`.
///
/// If any error is encountered, the provided `element` is returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ import Combine
import RxSwift

extension Publisher {

/// A bridging function that transforms a Combine `Publisher` into an RxSwift `Observable`.
///
/// - Returns: An RxSwift `Observable` that is the bridged transformation of the given `Publisher`.
///
public func asObservable() -> Observable<Output> {
return .create { observer -> Disposable in

let cancellable = sink(
receiveCompletion: { completion in
switch completion {
case .finished: observer.onCompleted()
case .failure(let error): observer.onError(error)
case .finished: observer.onCompleted()
case .failure(let error): observer.onError(error)
}
},
receiveValue: { observer.onNext($0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ public enum BridgeBufferingStrategy {
}

extension BridgeBufferingStrategy {

var strategy: Publishers.BufferingStrategy<BridgeFailure> {
switch self {
case .error: return .customError { .bufferOverflow }
case .dropNewest: return .dropNewest
case .dropOldest: return .dropOldest
case .error: return .customError { .bufferOverflow }
case .dropNewest: return .dropNewest
case .dropOldest: return .dropOldest
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ public enum InfallibleBridgeBufferingStrategy {
}

extension InfallibleBridgeBufferingStrategy {

var strategy: Publishers.BufferingStrategy<Never> {
switch self {
case .dropNewest: return .dropNewest
case .dropOldest: return .dropOldest
case .dropNewest: return .dropNewest
case .dropOldest: return .dropOldest
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Combine
import RxSwift

extension InfallibleType {

/// A bridging function that transforms an RxSwift `InfallibleType` into a Combine `Publisher`.
///
/// There is a fundamental difference between Combine and RxSwift around the concept of back pressure and how it is handled.
Expand All @@ -26,7 +25,6 @@ extension InfallibleType {
withBufferSize size: Int,
andBridgeBufferingStrategy whenFull: InfallibleBridgeBufferingStrategy
) -> Publishers.Buffer<InfallibleTypeBridgePublisher<Self>> {

return InfallibleTypeBridgePublisher(upstream: self)
.buffer(size: size, prefetch: .byRequest, whenFull: whenFull.strategy)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Combine
import RxSwift

extension ObservableType {

/// A bridging function that transforms an RxSwift `ObservableType` into a Combine `Publisher`.
///
/// There is a fundamental difference between Combine and RxSwift around the concept of back pressure and how it is handled.
Expand All @@ -29,13 +28,12 @@ extension ObservableType {
withBufferSize size: Int,
andBridgeBufferingStrategy whenFull: BridgeBufferingStrategy
) -> Publishers.MapError<Publishers.Buffer<ObservableTypeBridgePublisher<Self>>, Error> {

return ObservableTypeBridgePublisher(upstream: self)
.buffer(size: size, prefetch: .byRequest, whenFull: whenFull.strategy)
.mapError { error -> Error in
switch error {
case BridgeFailure.upstreamError(let upstreamError): return upstreamError
default: return error
case let BridgeFailure.upstreamError(upstreamError): return upstreamError
default: return error
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Foundation
import Combine

extension Publisher {

/// Convenience method whose default implementation causes a `preconditionFailure` when an upstream `BridgePublisher`'s buffer overflows.
/// In the event this does not occur, the failure type is mapped to the `Error` type of the upstream `Observable`.
///
Expand All @@ -18,13 +17,12 @@ extension Publisher {
public func assertBridgeBufferDoesNotOverflowIfPossible(
onBufferOverflow: @escaping () -> Error = { preconditionFailure("Bridge buffer overflowed.") }
) -> Publishers.MapError<Self, Error> {

return mapError { error -> Error in
guard let bridgeFailure = error as? BridgeFailure else { return error }

switch bridgeFailure {
case .bufferOverflow: return onBufferOverflow()
case .upstreamError(let upstreamError): return upstreamError
case .bufferOverflow: return onBufferOverflow()
case let .upstreamError(upstreamError): return upstreamError
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import RxSwift

/// A `Publisher` that handles subscriptions from an upstream `InfallibleType`.
public struct InfallibleTypeBridgePublisher<U: InfallibleType>: Publisher {

public typealias Output = U.Element
public typealias Failure = Never

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import RxSwift

/// A `Publisher` that handles subscriptions from an upstream `ObservableType`.
public struct ObservableTypeBridgePublisher<U: ObservableType>: Publisher {

public typealias Output = U.Element
public typealias Failure = BridgeFailure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@ import Foundation
import RxSwift

// MARK: - ObservableType
extension BridgeSubscription.Witness where U: ObservableType, U.Element == D.Input, D.Failure == BridgeFailure {

extension BridgeSubscription.Witness where U: ObservableType, U.Element == D.Input, D.Failure == BridgeFailure {
static var observableType: Self {
Self(
subscribe: { upstream, downstream in
upstream
.subscribe(
onNext: { value in _ = downstream.receive(value) },
onError: { error in downstream.receive(completion: .failure(.upstreamError(error))) },
onCompleted: { downstream.receive(completion: .finished) }
)
upstream.subscribe(
onNext: { value in _ = downstream.receive(value) },
onError: { error in downstream.receive(completion: .failure(.upstreamError(error))) },
onCompleted: { downstream.receive(completion: .finished) }
)
}
)
}
}

// MARK: - InfallibleType
extension BridgeSubscription.Witness where U: InfallibleType, U.Element == D.Input, D.Failure == Never {

extension BridgeSubscription.Witness where U: InfallibleType, U.Element == D.Input, D.Failure == Never {
static var infallibleType: Self {
Self(
subscribe: { upstream, downstream in
upstream
.subscribe(
onNext: { value in _ = downstream.receive(value) },
onCompleted: { downstream.receive(completion: .finished) }
)
upstream.subscribe(
onNext: { value in _ = downstream.receive(value) },
onCompleted: { downstream.receive(completion: .finished) }
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Combine
import RxSwift

final class BridgeSubscription<Upstream, Downstream: Subscriber>: Subscription {

enum Status {
case active(disposeBag: DisposeBag)
case pending
Expand Down

0 comments on commit 3939763

Please sign in to comment.