title: How to remove an item from list in typesafe config?
body: <p>In Typesafe configuration there is a very useful operator <code>+=</code> which appends a value to an existing list of values. Is there a way to do a reverse, i.e. to remove an item from existing list? </p>
  
  <p>In newer versions of Play Framework (2.4+) <code>+=</code> operator is used to tell the dependency injection container which modules are enabled or disabled. </p>
  
  <pre><code>play {
    modules {
      disabled += "play.api.cache.EhCacheModule"
      enabled += "com.github.mumoshu.play2.memcached.MemcachedModule"
    }
  }
  </code></pre>
  
  <p>Typesafe config also supports including configuration files into one another and this is often used to <a href="https://www.playframework.com/documentation/2.5.x/ProductionConfiguration" rel="nofollow noreferrer" title="override configurations for different environments">partially override configuration in different environments</a>. Unfortunately Play treats <code>enabled</code> and <code>disabled</code> lists as sets and once a module is added to <code>disabled</code> list there is no way to enable it back. This has been a source of issues and even a <a href="https://www.playframework.com/documentation/2.5.x/PluginsToModules" rel="nofollow noreferrer">special note is given in Play's documentation</a> discouraging use of <code>disabled</code> list.</p>
  
  <blockquote>
    <p>Note: If you are working on a library, it is highly discouraged to use play.modules.disabled to disable modules, as it can lead to nondeterministic results when modules are loaded by the application (see this issue for reasons on why you should not touch play.modules.disabled). In fact, play.modules.disabled is intended for end users to be able to override what modules are enabled by default.</p>
  </blockquote>
  
  <p>To be able to conditionally disable modules I came up with an ugly workaround using a feature of typesafe config allowing variable substitutions</p>
  
  <p>In <code>application.conf</code> I have </p>
  
  <pre><code>play {
    modules {
      disabled +=  ${memcached.disabled}"com.github.mumoshu.play2.memcached.MemcachedModule"
    }
  }
  
  memcached.disabled = ""
  </code></pre>
  
  <p>And then in <code>production.conf</code> I put something like this</p>
  
  <pre><code>include "application.conf"
  
  memcached.disabled = "x"
  play.modules.disabled += "play.api.cache.EhCacheModule"
  </code></pre>
  
  <p>so when <code>production.conf</code> is used it mangles the disabling in <code>application.conf</code>. Clearly this is not an acceptable solution.</p>