 class Changing<Value>: Observable {
   typealias ObservedValue = Value
 
-  private let retainedObserved: AnyObject         // This is to keep the observed object alive.
+  private     let retainedObserved: Any               // This is to keep the observed object alive.
   fileprivate var accumulator:      Value             // Encapsulated accumulator value
-  private var changes:          Changes<Value>    // Stream of accumulator changes
+  private     var changes:          Changes<Value>    // Stream of accumulator changes
 
   /// Constructs an accumulator with the given initial value, which is fed by an observed object by applying an
   /// accumulation function to the current accumulator value and the observed change to determine the new accumulator


/// Abstract interface to issuing announcements for a stream of changes over time.
///
protocol Announcable: class {

  /// The type of anounced values.
  ///

  }
}

/// Proxy to allow observations without the ability to announce changes.
///
struct ChangesOutlet<Value>: Observable {
  typealias ObservedValue  = Value

  private let changes: Changes<Value>

  // Swift compiler doesn't generate the right init in the face of the generic arguments.
  init(changes: Changes<Value>) { self.changes = changes }

  /// Registers an observer together with a context object whose lifetime determines the duration of the observation.
  ///
  /// The context object is stored using a weak reference. (It cannot be fully parametric as only objects can have
  /// weak references.)
  ///
  /// The observer will be called on the same thread where a new value is announced.
  ///
  @discardableResult
  func observe<Context : AnyObject>(withContext context: Context, observer: @escaping (Context, Value) -> ())
    -> Observation<Value>
  {
    return changes.observe(withContext: context, observer: observer)
  }
}

/// Proxy to allow announcements without the ability to observe changes.
///
struct ChangesInlet<Value>: Announcable {
  typealias AnnouncedValue  = Value

  private let changes: Changes<Value>

  // Swift compiler doesn't generate the right init in the face of the generic arguments.
  init(changes: Changes<Value>) { self.changes = changes }

  /// Announce a change to all observers.
  ///
  internal func announce(change: Value) {
    changes.announce(change: change)
  }
}

extension Changes {

  /// An inlet for the steam of changes.
  ///
  var inlet: ChangesInlet<Value> { return ChangesInlet(changes: self) }

  /// An outlet for the steam of changes.
  ///
  var outlet: ChangesOutlet<Value> { return ChangesOutlet(changes: self) }
}

/// Trigger streams are changes that only convey a point in time.
///
typealias Triggers = Changes<()>
