 public struct Middlewares<ReactorState: State> {
     private(set) var middleware: AnyMiddleware
 }
+
+
+// MARK: - Subscribers
 
 public protocol AnySubscriber: class {
     func _update(with state: Any)

        middlewares.forEach { $0.middleware._process(event: event, state: state) }
    }
    
    public func fire(emitter: EventEmitter) {
        if let event = emitter(state, self) {
            fire(event: event)
        }
    }
    
}

import Foundation



// MARK: - State

public protocol State {
    mutating func react(to event: Event)
}


// MARK: - Events

public protocol Event {}


// MARK: - Commands

public protocol AnyCommand {
    func _execute(state: Any, reactor: Any)
}

public protocol Command: AnyCommand {
    associatedtype S: State
    func execute(state: S, reactor: Reactor<S>)
}

extension Command {
    func _execute(state: Any, reactor: Any) {
        if let state = state as? S, let reactor = reactor as? Reactor<S> {
            execute(state: state, reactor: reactor)
        }
    }
}


// MARK: - Middlewares

public protocol AnyMiddleware {
    func _process(event: Event, state: Any)
