Skip to content

Commit

Permalink
Updated for Swift 3.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloutiertyler committed Oct 16, 2016
1 parent 041dad4 commit a18efbc
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 55 deletions.
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import PackageDescription
let package = Package(
name: "Reflex",
dependencies: [
.Package(url: "https://github.com/Zewo/Log.git", majorVersion: 0, minor: 9)
]
)
8 changes: 4 additions & 4 deletions Sources/Bag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

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

private init(identifier: UInt) {
fileprivate init(identifier: UInt) {
self.identifier = identifier
}
}

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

public init() {
Expand Down Expand Up @@ -105,4 +105,4 @@ extension BagElement: CustomStringConvertible {
var description: String {
return "BagElement(\(value))"
}
}
}
26 changes: 13 additions & 13 deletions Sources/ColdSignal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import Foundation

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

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

private var cancelDisposable: Disposable?

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

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

public func start() {
let observer = Observer<Value, Error> { event in
let observer = Observer<Value, ErrorType> { event in
if case .Interrupted = event {

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

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

Expand All @@ -117,7 +117,7 @@ extension ColdSignalType {
///
/// Returns a Disposable which can be used to dispose of the added observer.
@discardableResult
public func start(with observer: Observer<Value, Error>) -> Disposable? {
public func start(with observer: Observer<Value, ErrorType>) -> Disposable? {
let disposable = add(observer: observer)
start()
return disposable
Expand All @@ -128,7 +128,7 @@ extension ColdSignalType {
///
/// Returns a Disposable which can be used to dispose of the added observer.
@discardableResult
public func start(_ observerAction: Observer<Value, Error>.Action) -> Disposable? {
public func start(_ observerAction: @escaping Observer<Value, ErrorType>.Action) -> Disposable? {
return start(with: Observer(observerAction))
}

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

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

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

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

Expand Down
10 changes: 5 additions & 5 deletions Sources/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import Foundation
///
/// Signals must conform to the grammar:
/// `Next* (Failed | Completed | Interrupted)?`
public enum Event<Value, Error: ErrorProtocol> {
public enum Event<Value, ErrorType: Error> {

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

/// The signal terminated because of an error. No further events will be
/// received.
case Failed(Error)
case Failed(ErrorType)

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

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

/// Lifts the given function over the event's error.
public func mapError<F>(_ f: (Error) -> F) -> Event<Value, F> {
public func mapError<F>(_ f: (ErrorType) -> F) -> Event<Value, F> {
switch self {
case let .Next(value):
return .Next(value)
Expand Down Expand Up @@ -94,7 +94,7 @@ public enum Event<Value, Error: ErrorProtocol> {
}
}

public func == <Value: Equatable, Error: Equatable> (lhs: Event<Value, Error>, rhs: Event<Value, Error>) -> Bool {
public func == <Value: Equatable, ErrorType: Equatable> (lhs: Event<Value, ErrorType>, rhs: Event<Value, ErrorType>) -> Bool {
switch (lhs, rhs) {
case let (.Next(left), .Next(right)):
return left == right
Expand Down
12 changes: 6 additions & 6 deletions Sources/Observer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import Foundation

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

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

public let action: Action

public init(_ action: Action) {
public init(_ action: @escaping Action) {
self.action = action
}

/// Creates an Observer with an action which calls each of the provided
/// callbacks
public init(
failed: ((Error) -> Void)? = nil,
failed: ((ErrorType) -> Void)? = nil,
completed: (() -> Void)? = nil,
interrupted: (() -> Void)? = nil,
next: ((Value) -> Void)? = nil)
Expand All @@ -46,7 +46,7 @@ public struct Observer<Value, Error: ErrorProtocol> {
}


public func sendEvent(_ event: Event<Value, Error>) {
public func sendEvent(_ event: Event<Value, ErrorType>) {
action(event)
}

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

/// Puts an `Failed` event into the given observer.
public func sendFailed(_ error: Error) {
public func sendFailed(_ error: ErrorType) {
action(.Failed(error))
}

Expand Down
Loading

0 comments on commit a18efbc

Please sign in to comment.