title: Purely functional feedback suppression?
body: <p>I have a problem that I can solve reasonably easy with classic imperative programming using state: I'm writing a co-browsing app that shares URL's between several nodes. The program has a module for communication that I call <code>link</code> and for browser handling that I call <code>browser</code>. Now when a URL arrives in <code>link</code> i use the <code>browser</code> module to tell the 
  actual web browser to start loading the URL.</p>
  
  <p>The actual browser will trigger the navigation detection that the incoming URL has started to load, and hence will immediately be presented as a candidate for sending to the other side. That must be avoided, since it would create an infinite loop of link-following to the same URL, along the line of the following (very conceptualized) pseudo-code (it's Javascript, but please consider that a somewhat irrelevant implementation detail):</p>
  
  <pre><code>actualWebBrowser.urlListen.gotURL(function(url) {
    // Browser delivered an URL
    browser.process(url);
  });
  link.receivedAnURL(function(url) {
    actualWebBrowser.loadURL(url); // will eventually trigger above listener
  });
  </code></pre>
  
  <p>What I did first wast to store every incoming URL in <code>browser</code> and simply eat the URL immediately when it arrives, then remove it from a 'received' list in <code>browser</code>, along the lines of this:</p>
  
  <pre><code>browser.recents = {} // &lt;--- mutable state
  browser.recentsExpiry = 40000;
  
  browser.doSend = function(url) {
    now = (new Date).getTime();
    link.sendURL(url); // &lt;-- URL goes out on the network
  
    // Side-effect, mutating module state, clumsy clean up mechanism :(
    browser.recents[url] = now;
    setTimeout(function() { delete browser.recents[url] }, browser.recentsExpiry);
  
    return true;
  }
  browser.process = function(url) {
    if(/* sanity checks on `url`*/) {
      now = (new Date).getTime();
      var duplicate = browser.recents[url];
      if(! duplicate) return browser.doSend(url);
      if((now - duplicate_t) &gt; browser.recentsExpiry) {
        return browser.doSend(url);
      }
      return false;
    }
  }
  </code></pre>
  
  <p>It works but I'm a bit disappointed by my solution because of my habitual use of mutable state in <code>browser</code>. Is there a "Better Way (tm)" using immutable data structures/functional programming or the like for a situation like this?</p>