Skip to content

Commit ffaccdc

Browse files
committed
Style updates.
1 parent 59769ac commit ffaccdc

File tree

8 files changed

+147
-142
lines changed

8 files changed

+147
-142
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a Swift implementation of the [Reactive Streams](http://www.reactive-str
44

55
## Requirements
66

7-
Swift 3.0 snapshot required.
7+
Swift 3.0 development toolchain required.
88

99
## References
1010

Sources/AnyProcessor.swift

Lines changed: 38 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Sources/AnyPublisher.swift

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,40 @@ import Foundation
2020
///
2121
/// Forwards operations to an arbitrary underlying publisher with the same
2222
/// `PublishType` type, hiding the specifics of the underlying publisher.
23-
public struct AnyPublisher<Publish>: Publisher {
23+
public struct AnyPublisher<Element> : Publisher {
2424
/// The type of elements to be published.
25-
public typealias PublishType = Publish
25+
public typealias PublishType = Element
2626

2727
/// The boxed publisher which will receive forwarded calls.
28-
private let box: _AnyPublisherBoxBase<PublishType>
28+
private let _box: _AnyPublisherBox<PublishType>
2929

3030
/// Create a type erased wrapper around a publisher.
3131
///
3232
/// - parameter box: The publisher to receive operations.
33-
public init<P: Publisher where P.PublishType == PublishType>(_ box: P) {
34-
self.box = _AnyPublisherBox(box)
33+
public init<P: Publisher where P.PublishType == PublishType>(_ base: P) {
34+
_box = _PublisherBox(base)
3535
}
3636

3737
/// Forward `subscribe(subscriber:)` to the boxed publisher.
38-
public func subscribe<S: Subscriber where S.SubscribeType == PublishType>(subscriber: S) {
39-
box.subscribe(subscriber: subscriber)
40-
}
41-
42-
/// Erases type of the publisher and returns the canonical publisher.
43-
///
44-
/// - returns: type erased publisher.
45-
public func asPublisher() -> AnyPublisher<PublishType> {
46-
return self
38+
public func subscribe<S : Subscriber where S.SubscribeType == PublishType>(subscriber: S) {
39+
_box.subscribe(subscriber: subscriber)
4740
}
4841
}
4942

50-
public extension Publisher {
51-
/// Erases type of the publisher and returns the canonical publisher.
52-
///
53-
/// - returns: type erased publisher.
54-
public func asPublisher() -> AnyPublisher<PublishType> {
55-
return AnyPublisher(self)
56-
}
57-
}
58-
59-
private class _AnyPublisherBox<P: Publisher>: _AnyPublisherBoxBase<P.PublishType> {
60-
let box: P
43+
internal final class _PublisherBox<P : Publisher> : _AnyPublisherBox<P.PublishType> {
44+
private let _base: P
6145

62-
init(_ box: P) {
63-
self.box = box
46+
internal init(_ base: P) {
47+
self._base = base
6448
}
6549

66-
override func subscribe<S: Subscriber where S.SubscribeType == PublishType>(subscriber: S) {
67-
box.subscribe(subscriber: subscriber)
50+
internal override func subscribe<S : Subscriber where S.SubscribeType == P.PublishType>(subscriber: S) {
51+
_base.subscribe(subscriber: subscriber)
6852
}
6953
}
7054

71-
private class _AnyPublisherBoxBase<Publish>: Publisher {
72-
typealias PublishType = Publish
73-
74-
func subscribe<S: Subscriber where S.SubscribeType == PublishType>(subscriber: S) {
75-
fatalError()
55+
internal class _AnyPublisherBox<Element> {
56+
internal func subscribe<S : Subscriber where S.SubscribeType == Element>(subscriber: S) {
57+
_abstract()
7658
}
7759
}

Sources/AnySubscriber.swift

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,97 +20,79 @@ import Foundation
2020
///
2121
/// Forwards operations to an arbitrary underlying subscriber with the same
2222
/// `SubscribeTrype` type, hiding the specifics of the underlying subscriber.
23-
public struct AnySubscriber<Subscribe>: Subscriber {
23+
public struct AnySubscriber<Element> : Subscriber {
2424
/// The type of elements to be received.
25-
public typealias SubscribeType = Subscribe
25+
public typealias SubscribeType = Element
2626

2727
/// The boxed processor which will receive forwarded calls.
28-
private let box: _AnySubscriberBoxBase<SubscribeType>
28+
private let _box: _AnySubscriberBox<SubscribeType>
2929

3030
/// Create a type erased wrapper around a subscriber.
3131
///
3232
/// - parameter box: The subscriber to receive operations.
33-
public init<S: Subscriber where S.SubscribeType == SubscribeType>(_ box: S) {
34-
self.box = _AnySubscriberBox(box)
33+
public init<S : Subscriber where S.SubscribeType == SubscribeType>(_ base: S) {
34+
_box = _SubscriberBox(base)
3535
}
3636

3737
/// Forward `onSubscribe(subscription:)` to the boxed subscriber.
3838
public func onSubscribe(subscription: Subscription) {
39-
box.onSubscribe(subscription: subscription)
39+
_box.onSubscribe(subscription: subscription)
4040
}
4141

4242
/// Forward `onNext` to the boxed subscriber.
4343
public func onNext(element: SubscribeType) {
44-
box.onNext(element: element)
44+
_box.onNext(element: element)
4545
}
4646

4747
/// Forward `onError(error:)` to the boxed subscriber.
4848
public func onError(error: ErrorProtocol) {
49-
box.onError(error: error)
49+
_box.onError(error: error)
5050
}
5151

5252
/// Forward `onComplete()` to the boxed subscriber.
5353
public func onComplete() {
54-
box.onComplete()
55-
}
56-
57-
/// Erases type of the subscriber and returns the canonical subscriber.
58-
///
59-
/// - returns: type erased subscriber.
60-
public func asSubscriber() -> AnySubscriber<SubscribeType> {
61-
return self
54+
_box.onComplete()
6255
}
6356
}
6457

65-
public extension Subscriber {
66-
/// Erases type of the subscriber and returns the canonical processor.
67-
///
68-
/// - returns: type erased subscriber.
69-
public func asSubscriber() -> AnySubscriber<SubscribeType> {
70-
return AnySubscriber(self)
71-
}
72-
}
73-
74-
private class _AnySubscriberBox<S: Subscriber>: _AnySubscriberBoxBase<S.SubscribeType> {
75-
let box: S
58+
internal final class _SubscriberBox<S : Subscriber> : _AnySubscriberBox<S.SubscribeType> {
59+
private let _base: S
7660

77-
init(_ box: S) {
78-
self.box = box
61+
internal init(_ base: S) {
62+
self._base = _base
7963
}
8064

81-
override func onSubscribe(subscription: Subscription) {
82-
box.onSubscribe(subscription: subscription)
65+
internal override func onSubscribe(subscription: Subscription) {
66+
_base.onSubscribe(subscription: subscription)
8367
}
8468

85-
override func onNext(element: SubscribeType) {
86-
box.onNext(element: element)
69+
internal override func onNext(element: S.SubscribeType) {
70+
_base.onNext(element: element)
8771
}
8872

89-
override func onError(error: ErrorProtocol) {
90-
box.onError(error: error)
73+
internal override func onError(error: ErrorProtocol) {
74+
_base.onError(error: error)
9175
}
9276

93-
override func onComplete() {
94-
box.onComplete()
77+
internal override func onComplete() {
78+
_base.onComplete()
9579
}
9680
}
9781

98-
private class _AnySubscriberBoxBase<Subscribe>: Subscriber {
99-
typealias SubscribeType = Subscribe
100-
101-
func onSubscribe(subscription: Subscription) {
102-
fatalError()
82+
internal class _AnySubscriberBox<Element> {
83+
internal func onSubscribe(subscription: Subscription) {
84+
_abstract()
10385
}
10486

105-
func onNext(element: SubscribeType) {
106-
fatalError()
87+
internal func onNext(element: Element) {
88+
_abstract()
10789
}
10890

109-
func onError(error: ErrorProtocol) {
110-
fatalError()
91+
internal func onError(error: ErrorProtocol) {
92+
_abstract()
11193
}
11294

113-
func onComplete() {
114-
fatalError()
95+
internal func onComplete() {
96+
_abstract()
11597
}
11698
}

Sources/Processor.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,17 @@ import Foundation
1818

1919
/// A `Processor` represents a processing stage which is both a `Subscriber`
2020
/// and a `Publisher` and obeys the contracts of both.
21-
public protocol Processor: Subscriber, Publisher {
21+
public protocol Processor : Subscriber, Publisher {
22+
}
23+
24+
public extension Processor {
25+
/// Erases type of the processor and returns the canonical processor.
26+
///
27+
/// - returns: type erased publisher.
28+
public func asProcessor() -> AnyProcessor<SubscribeType, PublishType> {
29+
if let processor = self as? AnyProcessor<SubscribeType, PublishType> {
30+
return processor
31+
}
32+
return AnyProcessor(self)
33+
}
2234
}

0 commit comments

Comments
 (0)