Skip to content

Commit

Permalink
Adjust indent
Browse files Browse the repository at this point in the history
  • Loading branch information
inamiy committed Apr 1, 2019
1 parent 3f23750 commit ad48733
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 200 deletions.
200 changes: 100 additions & 100 deletions Sources/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,120 +2,120 @@ import Result
import Foundation
import Dispatch

/// Represents a signal event.
/// Represents a signal event.
///
/// Signals must conform to the grammar:
/// `value* (failed | completed | interrupted)?`
public enum Event<Value, Error: Swift.Error> {
/// A value provided by the signal.
case value(Value)

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

/// The signal successfully terminated. No further events will be received.
case completed

/// Event production on the signal has been interrupted. No further events
/// will be received.
///
/// Signals must conform to the grammar:
/// `value* (failed | completed | interrupted)?`
public enum Event<Value, Error: Swift.Error> {
/// A value provided by the signal.
case value(Value)

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

/// The signal successfully terminated. No further events will be received.
case completed

/// Event production on the signal has been interrupted. No further events
/// will be received.
///
/// - important: This event does not signify the successful or failed
/// completion of the signal.
case interrupted

/// Whether this event is a completed event.
public var isCompleted: Bool {
switch self {
case .completed:
return true

case .value, .failed, .interrupted:
return false
}
/// - important: This event does not signify the successful or failed
/// completion of the signal.
case interrupted

/// Whether this event is a completed event.
public var isCompleted: Bool {
switch self {
case .completed:
return true

case .value, .failed, .interrupted:
return false
}
}

/// Whether this event indicates signal termination (i.e., that no further
/// events will be received).
public var isTerminating: Bool {
switch self {
case .value:
return false
/// Whether this event indicates signal termination (i.e., that no further
/// events will be received).
public var isTerminating: Bool {
switch self {
case .value:
return false

case .failed, .completed, .interrupted:
return true
}
case .failed, .completed, .interrupted:
return true
}
}

/// Lift the given closure over the event's value.
///
/// - important: The closure is called only on `value` type events.
///
/// - parameters:
/// - f: A closure that accepts a value and returns a new value
///
/// - returns: An event with function applied to a value in case `self` is a
/// `value` type of event.
public func map<U>(_ f: (Value) -> U) -> Event<U, Error> {
switch self {
case let .value(value):
return .value(f(value))

case let .failed(error):
return .failed(error)

case .completed:
return .completed

case .interrupted:
return .interrupted
}
/// Lift the given closure over the event's value.
///
/// - important: The closure is called only on `value` type events.
///
/// - parameters:
/// - f: A closure that accepts a value and returns a new value
///
/// - returns: An event with function applied to a value in case `self` is a
/// `value` type of event.
public func map<U>(_ f: (Value) -> U) -> Event<U, Error> {
switch self {
case let .value(value):
return .value(f(value))

case let .failed(error):
return .failed(error)

case .completed:
return .completed

case .interrupted:
return .interrupted
}
}

/// Lift the given closure over the event's error.
///
/// - important: The closure is called only on failed type event.
///
/// - parameters:
/// - f: A closure that accepts an error object and returns
/// a new error object
///
/// - returns: An event with function applied to an error object in case
/// `self` is a `.Failed` type of event.
public func mapError<F>(_ f: (Error) -> F) -> Event<Value, F> {
switch self {
case let .value(value):
return .value(value)

case let .failed(error):
return .failed(f(error))

case .completed:
return .completed

case .interrupted:
return .interrupted
}
/// Lift the given closure over the event's error.
///
/// - important: The closure is called only on failed type event.
///
/// - parameters:
/// - f: A closure that accepts an error object and returns
/// a new error object
///
/// - returns: An event with function applied to an error object in case
/// `self` is a `.Failed` type of event.
public func mapError<F>(_ f: (Error) -> F) -> Event<Value, F> {
switch self {
case let .value(value):
return .value(value)

case let .failed(error):
return .failed(f(error))

case .completed:
return .completed

case .interrupted:
return .interrupted
}
}

/// Unwrap the contained `value` value.
public var value: Value? {
if case let .value(value) = self {
return value
} else {
return nil
}
/// Unwrap the contained `value` value.
public var value: Value? {
if case let .value(value) = self {
return value
} else {
return nil
}
}

/// Unwrap the contained `Error` value.
public var error: Error? {
if case let .failed(error) = self {
return error
} else {
return nil
}
/// Unwrap the contained `Error` value.
public var error: Error? {
if case let .failed(error) = self {
return error
} else {
return nil
}
}
}

extension Event where Value: Equatable, Error: Equatable {
public static func == (lhs: Event<Value, Error>, rhs: Event<Value, Error>) -> Bool {
Expand Down
Loading

0 comments on commit ad48733

Please sign in to comment.