Skip to content

Instantly share code, notes, and snippets.

@joshka
Created January 2, 2011 13:45
Show Gist options
  • Save joshka/762538 to your computer and use it in GitHub Desktop.
Save joshka/762538 to your computer and use it in GitHub Desktop.
private static IEnumerable<TSource> SkipWhileImpl<TSource>(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
using (IEnumerator<TSource> iterator = source.GetEnumerator())
{
do
{
if (!iterator.MoveNext())
yield break;
} while (predicate(iterator.Current));
do
{
yield return iterator.Current;
} while (iterator.MoveNext());
}
}
private static IEnumerable<TSource> SkipWhileImpl<TSource>(
IEnumerable<TSource> source,
Func<TSource, int, bool> predicate)
{
using (IEnumerator<TSource> iterator = source.GetEnumerator())
{
int index = 0;
do
{
if (!iterator.MoveNext())
yield break;
} while (predicate(iterator.Current, index++));
do
{
yield return iterator.Current;
} while (iterator.MoveNext());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment