title: How to implement the Observer Design Pattern in a pure functional way?
body: <p>Let's say I want to implement an event bus using a OO programming language.
  I could do this (pseudocode):</p>
  
  <pre><code>class EventBus
  
      listeners = []
  
      public register(listener):
          listeners.add(listener)
  
      public unregister(listener):
          listeners.remove(listener)
  
      public fireEvent(event):
          for (listener in listeners):
              listener.on(event)
  </code></pre>
  
  <p>This is actually the the observer pattern, but used for event-driven control flow of an application.</p>
  
  <p>How would you implement this pattern using a functional programming language (such as one of the lisp flavors)?</p>
  
  <p>I ask this because if one doesn't use objects, one would still need some kind of state to maintain a collection of all the listeners. More over, since the listeners collection changes over time, it would not be possible to create a pure functional solution, right?</p>