@@ -21,114 +21,95 @@ import Foundation
2121/// Forwards operations to an arbitrary underlying processor with the same
2222/// `SubscribeTrype` and `PublishType` types, hiding the specifics of the
2323/// underlying processor.
24- public struct AnyProcessor < Subscribe , Publish > : Processor {
24+ public struct AnyProcessor < ElementIn , ElementOut > : Processor {
2525 /// The type of elements to be received.
26- public typealias SubscribeType = Subscribe
26+ public typealias SubscribeType = ElementIn
2727
2828 /// The type of elements to be published.
29- public typealias PublishType = Publish
29+ public typealias PublishType = ElementOut
3030
3131 /// The boxed processor which will receive forwarded calls.
32- private let box : _AnyProcessorBoxBase < SubscribeType , PublishType >
32+ private let _box : _AnyProcessorBox < SubscribeType , PublishType >
3333
3434 /// Create a type erased wrapper around a processor.
3535 ///
3636 /// - parameter box: The processor to receive operations.
37- public init < P: Processor where P. SubscribeType == SubscribeType , P. PublishType == PublishType > ( _ box : P ) {
38- self . box = _AnyProcessorBox ( box )
37+ public init < P: Processor where P. SubscribeType == SubscribeType , P. PublishType == PublishType > ( _ base : P ) {
38+ _box = _ProcessorBox ( base )
3939 }
4040
4141 /// Forward `onSubscribe(subscription:)` to the boxed processor.
4242 public func onSubscribe( subscription: Subscription ) {
43- box . onSubscribe ( subscription: subscription)
43+ _box . onSubscribe ( subscription: subscription)
4444 }
4545
46- /// Forward `onNext` to the boxed processor.
46+ /// Forward `onNext() ` to the boxed processor.
4747 public func onNext( element: SubscribeType ) {
48- box . onNext ( element: element)
48+ _box . onNext ( element: element)
4949 }
5050
5151 /// Forward `onError(error:)` to the boxed processor.
5252 public func onError( error: ErrorProtocol ) {
53- box . onError ( error: error)
53+ _box . onError ( error: error)
5454 }
5555
5656 /// Forward `onComplete()` to the boxed processor.
5757 public func onComplete( ) {
58- box . onComplete ( )
58+ _box . onComplete ( )
5959 }
6060
6161 /// Forward `subscribe(subscriber:)` to the boxed processor.
62- public func subscribe< S: Subscriber where S. SubscribeType == PublishType > ( subscriber: S ) {
63- box. subscribe ( subscriber: subscriber)
64- }
65-
66- /// Erases type of the processor and returns the canonical processor.
67- ///
68- /// - returns: type erased processor.
69- public func asProcessor( ) -> AnyProcessor < SubscribeType , PublishType > {
70- return self
62+ public func subscribe< S : Subscriber where S. SubscribeType == PublishType > ( subscriber: S ) {
63+ _box. subscribe ( subscriber: subscriber)
7164 }
7265}
7366
74- public extension Processor {
75- /// Erases type of the processor and returns the canonical processor.
76- ///
77- /// - returns: type erased processor.
78- public func asProcessor( ) -> AnyProcessor < SubscribeType , PublishType > {
79- return AnyProcessor ( self )
80- }
81- }
82-
83- private class _AnyProcessorBox < P: Processor > : _AnyProcessorBoxBase < P . SubscribeType , P . PublishType > {
84- let box : P
67+ internal final class _ProcessorBox < P : Processor > : _AnyProcessorBox < P . SubscribeType , P . PublishType > {
68+ private let _base : P
8569
86- init ( _ box : P ) {
87- self . box = box
70+ internal init ( _ base : P ) {
71+ self . _base = base
8872 }
8973
90- override func onSubscribe( subscription: Subscription ) {
91- box . onSubscribe ( subscription: subscription)
74+ internal override func onSubscribe( subscription: Subscription ) {
75+ _base . onSubscribe ( subscription: subscription)
9276 }
9377
94- override func onNext( element: SubscribeType ) {
95- box . onNext ( element: element)
78+ internal override func onNext( element: P . SubscribeType ) {
79+ _base . onNext ( element: element)
9680 }
9781
98- override func onError( error: ErrorProtocol ) {
99- box . onError ( error: error)
82+ internal override func onError( error: ErrorProtocol ) {
83+ _base . onError ( error: error)
10084 }
10185
102- override func onComplete( ) {
103- box . onComplete ( )
86+ internal override func onComplete( ) {
87+ _base . onComplete ( )
10488 }
10589
106- override func subscribe< S: Subscriber where S. SubscribeType == PublishType > ( subscriber: S ) {
107- box . subscribe ( subscriber: subscriber)
90+ internal override func subscribe< S : Subscriber where S. SubscribeType == P . PublishType > ( subscriber: S ) {
91+ _base . subscribe ( subscriber: subscriber)
10892 }
10993}
11094
111- private class _AnyProcessorBoxBase < Subscribe, Publish> : Processor {
112- typealias SubscribeType = Subscribe
113- typealias PublishType = Publish
114-
115- func onSubscribe( subscription: Subscription ) {
116- fatalError ( )
95+ internal class _AnyProcessorBox < ElementIn, ElementOut> {
96+ internal func onSubscribe( subscription: Subscription ) {
97+ _abstract ( )
11798 }
11899
119- func onNext( element: SubscribeType ) {
120- fatalError ( )
100+ internal func onNext( element: ElementIn ) {
101+ _abstract ( )
121102 }
122103
123- func onError( error: ErrorProtocol ) {
124- fatalError ( )
104+ internal func onError( error: ErrorProtocol ) {
105+ _abstract ( )
125106 }
126107
127- func onComplete( ) {
128- fatalError ( )
108+ internal func onComplete( ) {
109+ _abstract ( )
129110 }
130111
131- func subscribe< S: Subscriber where S. SubscribeType == PublishType > ( subscriber: S ) {
132- fatalError ( )
112+ internal func subscribe< S : Subscriber where S. SubscribeType == ElementOut > ( subscriber: S ) {
113+ _abstract ( )
133114 }
134115}
0 commit comments