ThinkGeek - Cool Stuff for Geeks and Technophiles

You need a lazy sequence of something:

public static IEnumerable<T> Range<T>(T Start, T End, Func<T, T> inc) where T : IComparable<T>
{
   T result = Start;
   while (result.CompareTo(End) <= 0)
   {
      yield return result;
      result = inc(result) ;
   }
}

Need a sequence of integersĀ up to a million:

Funcs.Range(0, 1000000, (j => j + 1));

Need an infinite list of uppercase letters:

Funcs.Range('A', '[', (c => c >= 'Z' ? 'A' : (char)(c + 1)));

Comments are closed.