title: How can I fix the type errors for applying reduce on a MutableList of MutableSets to find the intersections of all sets?
body: <p>I'd like to find the intersections of <code>a</code>, <code>b</code> and <code>c</code>. Since I want to add more sets to the <code>lst</code>-object in the future, I defined it as a MutableList.</p>
  
  <pre><code>var a = mutableSetOf(1, 2, 3)
  var b = mutableSetOf(2, 3, 4)
  var c = mutableSetOf(3, 4, 5)
  var lst = mutableListOf(a, b, c)
  
  var intersection = lst.reduce {
      acc, currSet -&gt; acc.intersect(currSet)
  }
  </code></pre>
  
  <p>However, the last expression raises "invalid" due to failed type inference. (check <a href="https://pl.kotl.in/qbjCWo3J6" rel="nofollow noreferrer">this</a> playground)</p>
  
  <p>From the <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/reduce.html" rel="nofollow noreferrer">docs</a> I have the following signature for the <code>reduce</code> operation:</p>
  
  <pre><code>inline fun &lt;S, T : S&gt; Iterable&lt;T&gt;.reduce(
      operation: (acc: S, T) -&gt; S
  ): S
  </code></pre>
  
  <p>So why can't <code>S</code> and <code>T</code> be of the same type?</p>