Skip to content

Commit

Permalink
Documents TakeSkip and simplifies implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusschulz committed Sep 5, 2015
1 parent 1598315 commit c4a6c49
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/app/ExtraLINQ/IEnumerable/TakeSkip.cs
Expand Up @@ -4,6 +4,15 @@ namespace ExtraLinq
{
public static partial class EnumerableExtensions
{
/// <summary>
/// Iterates over the given sequence and repeatedly returns <paramref name="take"/> elements
/// and skips <paramref name="skip"/> elements.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The sequence to iterate over.</param>
/// <param name="take">The number of elements to take at each step.</param>
/// <param name="skip">The number of elements to skip after each step.</param>
/// <returns>A sequence containing the taken elements.</returns>
public static IEnumerable<TSource> TakeSkip<TSource>(this IEnumerable<TSource> source, int take, int skip)
{
ThrowIf.Argument.IsNull(source, "source");
Expand All @@ -21,24 +30,16 @@ private static IEnumerable<TSource> TakeSkipIterator<TSource>(IEnumerable<TSourc
{
for (int i = 0; i < take; i++)
{
bool hasNext = enumerator.MoveNext();

if (!hasNext)
{
if (!enumerator.MoveNext())
yield break;
}

yield return enumerator.Current;
}

for (int i = 0; i < skip; i++)
{
bool hasNext = enumerator.MoveNext();

if (!hasNext)
{
if (!enumerator.MoveNext())
yield break;
}
}
}
}
Expand Down

0 comments on commit c4a6c49

Please sign in to comment.