title: C# List ConvertAll with Index
body: <p>Consider an input list, X, consisting of objects of type Tx, for which you need to run one of several functions, y_a = A(x), y_b = B(x), etc... (all of which output objects of Ty) to generate an output list, Y. Finally, the choice of conversion functions is a function of the index of the element within the list. </p>
  
  <p>Ideally, the solution would be a one-liner (I'm looking at you, Linq).</p>
  
  <p>To put it in code:</p>
  
  <pre><code>public OtherType ConversionA (int n) {
  }
  
  public OtherType ConversionB (int n) {
  }
  
  class MyClass {
    public MyClass (List&lt;int&gt; values) 
      : this (values.ConvertAllWithIndex((value, index) =&gt; 
        UseConversionA (index) ? ConversionA (value) : ConversionB (value)) {
    }
  
    public MyClass (List&lt;OtherType&gt; things) {
      ...
    }
  
    bool UseConversionA (int index) {
      ...
    }
  }
  </code></pre>
  
  <p>I realize an easier solution for this sample code would be to perform the conversion from X to Y prior to calling MyClass and simply passing Y, but bear with me, as this is a contrived example to see if someone knows a way to replicate ConvertAll that is conditioned on the index the target element.</p>
  
  <p>Also, one could create an extension to Tx to make a custom ConvertAll with index, but I'm curious if can figure out a way to make Linq (or otherwise) achieve this.</p>