Skip to content

Commit a18efbc

Browse files
committed
Updated for Swift 3.0 release.
1 parent 041dad4 commit a18efbc

File tree

7 files changed

+54
-55
lines changed

7 files changed

+54
-55
lines changed

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ import PackageDescription
33
let package = Package(
44
name: "Reflex",
55
dependencies: [
6-
.Package(url: "https://github.com/Zewo/Log.git", majorVersion: 0, minor: 9)
76
]
87
)

Sources/Bag.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
/// A token for the identification of an item in a Bag.
1010
public final class RemovalToken {
11-
private var identifier: UInt?
11+
fileprivate var identifier: UInt?
1212

13-
private init(identifier: UInt) {
13+
fileprivate init(identifier: UInt) {
1414
self.identifier = identifier
1515
}
1616
}
1717

1818
/// An unordered, non-unique collection of values of type `Element`.
1919
public struct Bag<Element> {
20-
private var elements: [BagElement<Element>] = []
20+
fileprivate var elements: [BagElement<Element>] = []
2121
private var currentIdentifier: UInt = 0
2222

2323
public init() {
@@ -105,4 +105,4 @@ extension BagElement: CustomStringConvertible {
105105
var description: String {
106106
return "BagElement(\(value))"
107107
}
108-
}
108+
}

Sources/ColdSignal.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
import Foundation
1010

11-
public final class ColdSignal<Value, Error: ErrorProtocol>: ColdSignalType, InternalSignalType, SpecialSignalGenerator {
12-
internal var observers = Bag<Observer<Value, Error>>()
11+
public final class ColdSignal<Value, ErrorType: Error>: ColdSignalType, InternalSignalType, SpecialSignalGenerator {
12+
internal var observers = Bag<Observer<Value, ErrorType>>()
1313

14-
private let startHandler: (Observer<Value, Error>) -> Disposable?
14+
private let startHandler: (Observer<Value, ErrorType>) -> Disposable?
1515

1616
private var cancelDisposable: Disposable?
1717

@@ -28,7 +28,7 @@ public final class ColdSignal<Value, Error: ErrorProtocol>: ColdSignalType, Inte
2828
///
2929
/// Invoking `start()` will have no effect until the signal is stopped. After
3030
/// `stop()` is called this process may be repeated.
31-
public init(_ generator: (Observer<Value, Error>) -> Disposable?) {
31+
public init(_ generator: @escaping (Observer<Value, ErrorType>) -> Disposable?) {
3232
self.startHandler = generator
3333
}
3434

@@ -39,7 +39,7 @@ public final class ColdSignal<Value, Error: ErrorProtocol>: ColdSignalType, Inte
3939
/// with the signal and immediately send an `Interrupted` event.
4040

4141
public func start() {
42-
let observer = Observer<Value, Error> { event in
42+
let observer = Observer<Value, ErrorType> { event in
4343
if case .Interrupted = event {
4444

4545
self.interrupt()
@@ -79,7 +79,7 @@ public final class ColdSignal<Value, Error: ErrorProtocol>: ColdSignalType, Inte
7979
///
8080
/// Returns a Disposable which can be used to disconnect the observer. Disposing
8181
/// of the Disposable will have no effect on the Signal itself.
82-
public func add(observer: Observer<Value, Error>) -> Disposable? {
82+
public func add(observer: Observer<Value, ErrorType>) -> Disposable? {
8383
let token = self.observers.insert(value: observer)
8484
return ActionDisposable {
8585
self.observers.removeValueForToken(token: token)
@@ -91,7 +91,7 @@ public final class ColdSignal<Value, Error: ErrorProtocol>: ColdSignalType, Inte
9191
extension ColdSignal: CustomDebugStringConvertible {
9292

9393
public var debugDescription: String {
94-
let obs = Array(self.observers.map { String($0) })
94+
let obs = Array(self.observers.map { String(describing: $0) })
9595
return "ColdSignal[\(obs.joined(separator: ", "))]"
9696
}
9797

@@ -117,7 +117,7 @@ extension ColdSignalType {
117117
///
118118
/// Returns a Disposable which can be used to dispose of the added observer.
119119
@discardableResult
120-
public func start(with observer: Observer<Value, Error>) -> Disposable? {
120+
public func start(with observer: Observer<Value, ErrorType>) -> Disposable? {
121121
let disposable = add(observer: observer)
122122
start()
123123
return disposable
@@ -128,7 +128,7 @@ extension ColdSignalType {
128128
///
129129
/// Returns a Disposable which can be used to dispose of the added observer.
130130
@discardableResult
131-
public func start(_ observerAction: Observer<Value, Error>.Action) -> Disposable? {
131+
public func start(_ observerAction: @escaping Observer<Value, ErrorType>.Action) -> Disposable? {
132132
return start(with: Observer(observerAction))
133133
}
134134

@@ -137,7 +137,7 @@ extension ColdSignalType {
137137
///
138138
/// Returns a Disposable which can be used to dispose of the added observer.
139139
@discardableResult
140-
public func startWithNext(next: (Value) -> Void) -> Disposable? {
140+
public func startWithNext(next: @escaping (Value) -> Void) -> Disposable? {
141141
return start(with: Observer(next: next))
142142
}
143143

@@ -146,7 +146,7 @@ extension ColdSignalType {
146146
///
147147
/// Returns a Disposable which can be used to dispose of the added observer.
148148
@discardableResult
149-
public func startWithCompleted(completed: () -> Void) -> Disposable? {
149+
public func startWithCompleted(completed: @escaping () -> Void) -> Disposable? {
150150
return start(with: Observer(completed: completed))
151151
}
152152

@@ -155,7 +155,7 @@ extension ColdSignalType {
155155
///
156156
/// Returns a Disposable which can be used to dispose of the added observer.
157157
@discardableResult
158-
public func startWithFailed(failed: (Error) -> Void) -> Disposable? {
158+
public func startWithFailed(failed: @escaping (ErrorType) -> Void) -> Disposable? {
159159
return start(with: Observer(failed: failed))
160160
}
161161

@@ -164,7 +164,7 @@ extension ColdSignalType {
164164
///
165165
/// Returns a Disposable which can be used to dispose of the added observer.
166166
@discardableResult
167-
public func startWithInterrupted(interrupted: () -> Void) -> Disposable? {
167+
public func startWithInterrupted(interrupted: @escaping () -> Void) -> Disposable? {
168168
return start(with: Observer(interrupted: interrupted))
169169
}
170170

Sources/Event.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import Foundation
1212
///
1313
/// Signals must conform to the grammar:
1414
/// `Next* (Failed | Completed | Interrupted)?`
15-
public enum Event<Value, Error: ErrorProtocol> {
15+
public enum Event<Value, ErrorType: Error> {
1616

1717
/// A value provided by the signal.
1818
case Next(Value)
1919

2020
/// The signal terminated because of an error. No further events will be
2121
/// received.
22-
case Failed(Error)
22+
case Failed(ErrorType)
2323

2424
/// The signal successfully terminated. No further events will be received.
2525
case Completed
@@ -42,7 +42,7 @@ public enum Event<Value, Error: ErrorProtocol> {
4242
}
4343

4444
/// Lifts the given function over the event's value.
45-
public func map<U>(_ f: (Value) -> U) -> Event<U, Error> {
45+
public func map<U>(_ f: (Value) -> U) -> Event<U, ErrorType> {
4646
switch self {
4747
case let .Next(value):
4848
return .Next(f(value))
@@ -59,7 +59,7 @@ public enum Event<Value, Error: ErrorProtocol> {
5959
}
6060

6161
/// Lifts the given function over the event's error.
62-
public func mapError<F>(_ f: (Error) -> F) -> Event<Value, F> {
62+
public func mapError<F>(_ f: (ErrorType) -> F) -> Event<Value, F> {
6363
switch self {
6464
case let .Next(value):
6565
return .Next(value)
@@ -94,7 +94,7 @@ public enum Event<Value, Error: ErrorProtocol> {
9494
}
9595
}
9696

97-
public func == <Value: Equatable, Error: Equatable> (lhs: Event<Value, Error>, rhs: Event<Value, Error>) -> Bool {
97+
public func == <Value: Equatable, ErrorType: Equatable> (lhs: Event<Value, ErrorType>, rhs: Event<Value, ErrorType>) -> Bool {
9898
switch (lhs, rhs) {
9999
case let (.Next(left), .Next(right)):
100100
return left == right

Sources/Observer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import Foundation
1010

1111
/// An Observer is a simple wrapper around a function which can receive Events
1212
/// (typically from a Signal).
13-
public struct Observer<Value, Error: ErrorProtocol> {
13+
public struct Observer<Value, ErrorType: Error> {
1414

15-
public typealias Action = (Event<Value, Error>) -> Void
15+
public typealias Action = (Event<Value, ErrorType>) -> Void
1616

1717
public let action: Action
1818

19-
public init(_ action: Action) {
19+
public init(_ action: @escaping Action) {
2020
self.action = action
2121
}
2222

2323
/// Creates an Observer with an action which calls each of the provided
2424
/// callbacks
2525
public init(
26-
failed: ((Error) -> Void)? = nil,
26+
failed: ((ErrorType) -> Void)? = nil,
2727
completed: (() -> Void)? = nil,
2828
interrupted: (() -> Void)? = nil,
2929
next: ((Value) -> Void)? = nil)
@@ -46,7 +46,7 @@ public struct Observer<Value, Error: ErrorProtocol> {
4646
}
4747

4848

49-
public func sendEvent(_ event: Event<Value, Error>) {
49+
public func sendEvent(_ event: Event<Value, ErrorType>) {
5050
action(event)
5151
}
5252

@@ -56,7 +56,7 @@ public struct Observer<Value, Error: ErrorProtocol> {
5656
}
5757

5858
/// Puts an `Failed` event into the given observer.
59-
public func sendFailed(_ error: Error) {
59+
public func sendFailed(_ error: ErrorType) {
6060
action(.Failed(error))
6161
}
6262

0 commit comments

Comments
 (0)