title: Merge multiple lists if condition is true
body: <p>I've been trying to wrap my head around this for a while now, but it seems like my lack of Haskell experience just won't get me through it. I couldn't find a similar question here on Stackoverflow (most of them are related to merging all sublists, without any condition)</p>
  
  <p>So here it goes. Let's say I have a list of lists like this:</p>
  
  <pre><code>[[1, 2, 3], [3, 5, 6], [20, 21, 22]]
  </code></pre>
  
  <p>Is there an efficient way to merge lists if some sort of condition is true? Let's say I need to merge lists that share at least one element. In case of example, result would be:</p>
  
  <pre><code>[[1, 2, 3, 3, 5, 6], [20, 21, 22]]
  </code></pre>
  
  <p>Another example (when all lists can be merged):</p>
  
  <pre><code>[[1, 2], [2, 3], [3, 4]]
  </code></pre>
  
  <p>And it's result:</p>
  
  <pre><code>[[1, 2, 2, 3, 3, 4]]
  </code></pre>
  
  <p>Thanks for your help!</p>