title: How to build a sequence using a fluent interface?
body: <p>I'm trying to using a fluent interface to build a collection, similar to this (simplified) example:</p>
  
  <pre><code>   var a = StartWith(1).Add(2).Add(3).Add(4).ToArray();
     /* a = int[] {1,2,3,4};  */
  </code></pre>
  
  <p>The best solution I can come up with add Add() as:</p>
  
  <pre><code>  IEnumerable&lt;T&gt; Add&lt;T&gt;(this IEnumerable&lt;T&gt; coll, T item)
    {
       foreach(var t in coll) yield return t;
       yield return item;
    }
  </code></pre>
  
  <p>Which seems to add a lot of overhead that going to be repeated in each call.</p>
  
  <p>IS there a better way?</p>
  
  <p>UPDATE:
  in my rush, I over-simplified the example, and left out an important requirement.   The last item in the existing coll influences the next item.  So, a slightly less simplified example:</p>
  
  <pre><code>   var a = StartWith(1).Times10Plus(2).Times10Plus(3).Times10Plus(4).ToArray();
     /* a = int[] {1,12,123,1234};  */
  
  public static IEnumerable&lt;T&gt; StartWith&lt;T&gt;(T x)
  {
      yield return x;
  }
  
  static public  IEnumerable&lt;int&gt; Times10Plus(this IEnumerable&lt;int&gt; coll, int item)
  {
      int last = 0;
      foreach (var t in coll)
      {
          last = t;
          yield return t;
      }
      yield return last * 10 + item;
  }
  </code></pre>