title: Combining list functions
body: <p>Below function calculates possible combinations of List elements.</p>
  
  <p>Elements of list which are same are not returned and also just unique elements are returned :</p>
  
  <pre><code>def combinations[T](l: List[T]): List[(T,T)] = l match {
      case Nil =&gt; Nil
      case h::Nil =&gt; Nil
      case h::t =&gt; t.map(x=&gt;(h,x)) ++ combinations(t)
  }
  </code></pre>
  
  <p>List(1,2,3) returns List((1,2),(1,3),(2,3))</p>
  
  <p>This solution (not mine) is elegant but I would like to know the intuition behind it. Is there a generic property of list elements contained within the code that I'm not aware of? I'm aware why this solution works but I'm unsure of how to arrive at this solution?</p>