 }
 
 extension Observable {
-
-  func completableSubject() -> CompletableSubject<Element> {
-    return CompletableSubject(source: self)
-  }
+  func completableSubject() -> CompletableSubject<Element> { CompletableSubject(source: self) }
 }
 
 class CompletableSubject<T> {
-
-  func asObservable() -> Observable<T> {
-    return self.subject.asObservable()
-  }
+  func asObservable() -> Observable<T> { self.subject.asObservable() }
 
   init(source: Observable<T>) {
     let subject = PublishSubject<T>()

/**
 `typealias` `StateType` and `ActionType` either within the class definition or in an extension.
 */
class ReduxTypes: ReduxContextType {
}

protocol ReducerType {

  associatedtype StateType
  associatedtype ActionType

  typealias ReduceTuple = (state: StateType, action: ActionType, modified: Bool)
  typealias ActionTypeErasedReduceTuple = (state: StateType, action: ReduxTypes.ActionType, modified: Bool)

  func typedReduce(_ tuple: ReduceTuple) -> ReduceTuple
}

extension ReducerType {

  func reduce(_ tuple: ActionTypeErasedReduceTuple) -> ActionTypeErasedReduceTuple {
    guard let typedTuple = tuple as? ReduceTuple else {
      return tuple

}

protocol EpicType: MiddlewareType {
  associatedtype EmitActionType

  init(emitter: ActionEmitter)
}

protocol UiComponent {
  associatedtype StateType

  init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType)
}

class ActionEmitter {
  let observable: Observable<ReduxTypes.ActionType>

  init() {
    self.observable = self.subject.asObservable().observeOn(self.scheduler)
  }

  func typedEmit<T>() -> (T) -> Void {
    { (action: T) in self.subject.onNext(action) }
  }

  func terminate() { self.subject.onCompleted() }

  deinit { self.subject.onCompleted() }

  private let scheduler = SerialDispatchQueueScheduler(qos: .userInteractive)
  private let subject = PublishSubject<ReduxTypes.ActionType>()
}

class ReduxContext {
  let actionEmitter = ActionEmitter()
  let stateSource: Observable<ReduxTypes.StateType>

  convenience init(
    initialState: ReduxTypes.StateType,
    reducers: [ReduxTypes.ReduceFunction],
    middlewares: [(@escaping ReduxTypes.ReduceFunction) -> ReduxTypes
      .ReduceFunction] = []
  ) {
    self.init(initialState: initialState)

    self.actionEmitter.observable
