Skip to content

Commit

Permalink
Renames item to element for more consistent naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusschulz committed Sep 5, 2015
1 parent d16b65f commit e00e38d
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 152 deletions.
18 changes: 9 additions & 9 deletions src/app/ExtraLINQ/IEnumerable/Cycle.cs
Expand Up @@ -22,31 +22,31 @@ private static IEnumerable<TSource> CycleIterator<TSource>(IEnumerable<TSource>
{
var collection = source as ICollection<TSource>;

var itemBuffer = collection == null
var elementBuffer = collection == null
? new List<TSource>()
: new List<TSource>(collection.Count);

foreach (TSource item in source)
foreach (TSource element in source)
{
yield return item;
yield return element;

// We add this item to a local item buffer so that
// We add this element to a local element buffer so that
// we don't have to enumerate the sequence multiple times
itemBuffer.Add(item);
elementBuffer.Add(element);
}

if (itemBuffer.IsEmpty())
if (elementBuffer.IsEmpty())
{
// If the item buffer is empty, so was the source sequence.
// If the element buffer is empty, so was the source sequence.
// In this case, we can stop here and simply return an empty sequence.
yield break;
}

int index = 0;
while (true)
{
yield return itemBuffer[index];
index = (index + 1) % itemBuffer.Count;
yield return elementBuffer[index];
index = (index + 1) % elementBuffer.Count;
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/app/ExtraLINQ/IEnumerable/HasAtLeast.cs
Expand Up @@ -8,56 +8,56 @@ namespace ExtraLinq
public static partial class EnumerableExtensions
{
/// <summary>
/// Determines whether the specified sequence's item count is equal to or greater than <paramref name="expectedMinItemCount"/>.
/// Determines whether the specified sequence's element count is equal to or greater than <paramref name="minElementCount"/>.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose items to count.</param>
/// <param name="expectedMinItemCount">The minimum number of items the specified sequence is expected to contain.</param>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose elements to count.</param>
/// <param name="minElementCount">The minimum number of elements the specified sequence is expected to contain.</param>
/// <returns>
/// <c>true</c> if the item count of <paramref name="source"/> is equal to or greater than <paramref name="expectedMinItemCount"/>; otherwise, <c>false</c>.
/// <c>true</c> if the element count of <paramref name="source"/> is equal to or greater than <paramref name="minElementCount"/>; otherwise, <c>false</c>.
/// </returns>
public static bool HasAtLeast<TSource>(this IEnumerable<TSource> source, int expectedMinItemCount)
public static bool HasAtLeast<TSource>(this IEnumerable<TSource> source, int minElementCount)
{
return HasAtLeast(source, expectedMinItemCount, _ => true);
return HasAtLeast(source, minElementCount, _ => true);
}

/// <summary>
/// Determines whether the specified sequence contains exactly <paramref name="expectedMinItemCount"/> or more items satisfying a condition.
/// Determines whether the specified sequence contains exactly <paramref name="minElementCount"/> or more elements satisfying a condition.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose items to count.</param>
/// <param name="expectedMinItemCount">The minimum number of items satisfying the specified condition the specified sequence is expected to contain.</param>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose elements to count.</param>
/// <param name="minElementCount">The minimum number of elements satisfying the specified condition the specified sequence is expected to contain.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <returns>
/// <c>true</c> if the item count of satisfying items is equal to or greater than <paramref name="expectedMinItemCount"/>; otherwise, <c>false</c>.
/// <c>true</c> if the element count of satisfying elements is equal to or greater than <paramref name="minElementCount"/>; otherwise, <c>false</c>.
/// </returns>
public static bool HasAtLeast<TSource>(this IEnumerable<TSource> source, int expectedMinItemCount, Func<TSource, bool> predicate)
public static bool HasAtLeast<TSource>(this IEnumerable<TSource> source, int minElementCount, Func<TSource, bool> predicate)
{
ThrowIf.Argument.IsNull(source, "source");
ThrowIf.Argument.IsNull(predicate, "predicate");
ThrowIf.Argument.IsNegative(expectedMinItemCount, "expectedMinItemCount");
ThrowIf.Argument.IsNegative(minElementCount, "minElementCount");

if (expectedMinItemCount == 0)
if (minElementCount == 0)
{
return true;
}

ICollection sourceCollection = source as ICollection;

if (sourceCollection != null && sourceCollection.Count < expectedMinItemCount)
if (sourceCollection != null && sourceCollection.Count < minElementCount)
{
// If the collection doesn't even contain as many items
// If the collection doesn't even contain as many elements
// as expected to match the predicate, we can stop here
return false;
}

int matches = 0;

foreach (TSource item in source.Where(predicate))
foreach (TSource element in source.Where(predicate))
{
matches++;

if (matches >= expectedMinItemCount)
if (matches >= minElementCount)
{
return true;
}
Expand Down
32 changes: 16 additions & 16 deletions src/app/ExtraLINQ/IEnumerable/HasAtMost.cs
Expand Up @@ -8,51 +8,51 @@ namespace ExtraLinq
public static partial class EnumerableExtensions
{
/// <summary>
/// Determines whether the specified sequence's item count is at most <paramref name="expectedMaxItemCount"/>.
/// Determines whether the specified sequence's element count is at most <paramref name="maxElementCount"/>.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose items to count.</param>
/// <param name="expectedMaxItemCount">The maximum number of items the specified sequence is expected to contain.</param>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose elements to count.</param>
/// <param name="maxElementCount">The maximum number of elements the specified sequence is expected to contain.</param>
/// <returns>
/// <c>true</c> if the item count of <paramref name="source"/> is equal to or lower than <paramref name="expectedMaxItemCount"/>; otherwise, <c>false</c>.
/// <c>true</c> if the element count of <paramref name="source"/> is equal to or lower than <paramref name="maxElementCount"/>; otherwise, <c>false</c>.
/// </returns>
public static bool HasAtMost<TSource>(this IEnumerable<TSource> source, int expectedMaxItemCount)
public static bool HasAtMost<TSource>(this IEnumerable<TSource> source, int maxElementCount)
{
return HasAtMost(source, expectedMaxItemCount, _ => true);
return HasAtMost(source, maxElementCount, _ => true);
}

/// <summary>
/// Determines whether the specified sequence contains at most <paramref name="expectedMaxItemCount"/> items satisfying a condition.
/// Determines whether the specified sequence contains at most <paramref name="maxElementCount"/> elements satisfying a condition.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose items to count.</param>
/// <param name="expectedMaxItemCount">The maximum number of items satisfying the specified condition the specified sequence is expected to contain.</param>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> whose elements to count.</param>
/// <param name="maxElementCount">The maximum number of elements satisfying the specified condition the specified sequence is expected to contain.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <returns>
/// <c>true</c> if the item count of satisfying items is equal to or less than <paramref name="expectedMaxItemCount"/>; otherwise, <c>false</c>.
/// <c>true</c> if the element count of satisfying elements is equal to or less than <paramref name="maxElementCount"/>; otherwise, <c>false</c>.
/// </returns>
public static bool HasAtMost<TSource>(this IEnumerable<TSource> source, int expectedMaxItemCount, Func<TSource, bool> predicate)
public static bool HasAtMost<TSource>(this IEnumerable<TSource> source, int maxElementCount, Func<TSource, bool> predicate)
{
ThrowIf.Argument.IsNull(source, "source");
ThrowIf.Argument.IsNull(predicate, "predicate");
ThrowIf.Argument.IsNegative(expectedMaxItemCount, "expectedMaxItemCount");
ThrowIf.Argument.IsNegative(maxElementCount, "maxElementCount");

ICollection sourceCollection = source as ICollection;

if (sourceCollection != null && sourceCollection.Count <= expectedMaxItemCount)
if (sourceCollection != null && sourceCollection.Count <= maxElementCount)
{
// If the collection doesn't contain more items
// If the collection doesn't contain more elements
// than expected to match the predicate, we can stop here
return true;
}

int matches = 0;

foreach (TSource item in source.Where(predicate))
foreach (TSource element in source.Where(predicate))
{
matches++;

if (matches > expectedMaxItemCount)
if (matches > maxElementCount)
{
return false;
}
Expand Down
36 changes: 18 additions & 18 deletions src/app/ExtraLINQ/IEnumerable/HasExactly.cs
Expand Up @@ -8,67 +8,67 @@ namespace ExtraLinq
public static partial class EnumerableExtensions
{
/// <summary>
/// Determines whether the specified sequence contains exactly the specified number of items.
/// Determines whether the specified sequence contains exactly the specified number of elements.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> to count.</param>
/// <param name="expectedItemCount">The number of items the specified sequence is expected to contain.</param>
/// <param name="elementCount">The number of elements the specified sequence is expected to contain.</param>
/// <returns>
/// <c>true</c> if <paramref name="source"/> contains exactly <paramref name="expectedItemCount"/> items; otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="source"/> contains exactly <paramref name="elementCount"/> elements; otherwise, <c>false</c>.
/// </returns>
public static bool HasExactly<TSource>(this IEnumerable<TSource> source, int expectedItemCount)
public static bool HasExactly<TSource>(this IEnumerable<TSource> source, int elementCount)
{
ThrowIf.Argument.IsNull(source, "source");
ThrowIf.Argument.IsNegative(expectedItemCount, "expectedItemCount");
ThrowIf.Argument.IsNegative(elementCount, "elementCount");

ICollection sourceCollection = source as ICollection;

if (sourceCollection != null)
{
return sourceCollection.Count == expectedItemCount;
return sourceCollection.Count == elementCount;
}

return HasExactly(source, expectedItemCount, _ => true);
return HasExactly(source, elementCount, _ => true);
}

/// <summary>
/// Determines whether the specified sequence contains exactly the specified number of items satisfying the specified condition.
/// Determines whether the specified sequence contains exactly the specified number of elements satisfying the specified condition.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> to count satisfying items.</param>
/// <param name="expectedItemCount">The number of matching items the specified sequence is expected to contain.</param>
/// <param name="source">The <see cref="IEnumerable{TSource}"/> to count satisfying elements.</param>
/// <param name="elementCount">The number of matching elements the specified sequence is expected to contain.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <returns>
/// <c>true</c> if <paramref name="source"/> contains exactly <paramref name="expectedItemCount"/> items satisfying the condition; otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="source"/> contains exactly <paramref name="elementCount"/> elements satisfying the condition; otherwise, <c>false</c>.
/// </returns>
public static bool HasExactly<TSource>(this IEnumerable<TSource> source, int expectedItemCount, Func<TSource, bool> predicate)
public static bool HasExactly<TSource>(this IEnumerable<TSource> source, int elementCount, Func<TSource, bool> predicate)
{
ThrowIf.Argument.IsNull(source, "source");
ThrowIf.Argument.IsNull(predicate, "predicate");
ThrowIf.Argument.IsNegative(expectedItemCount, "expectedItemCount");
ThrowIf.Argument.IsNegative(elementCount, "elementCount");

ICollection sourceCollection = source as ICollection;

if (sourceCollection != null && sourceCollection.Count < expectedItemCount)
if (sourceCollection != null && sourceCollection.Count < elementCount)
{
// If the collection doesn't even contain as many items
// If the collection doesn't even contain as many elements
// as expected to match the predicate, we can stop here
return false;
}

int matches = 0;

foreach (var item in source.Where(predicate))
foreach (var element in source.Where(predicate))
{
++matches;

if (matches > expectedItemCount)
if (matches > elementCount)
{
return false;
}
}

return matches == expectedItemCount;
return matches == elementCount;
}
}
}
4 changes: 2 additions & 2 deletions src/app/ExtraLINQ/IEnumerable/Intersperse.cs
Expand Up @@ -29,7 +29,7 @@ private static IEnumerable<TSource> IntersperseIterator<TSource>(IEnumerable<TSo
{
bool isFirst = true;

foreach (TSource item in source)
foreach (TSource element in source)
{
if (!isFirst)
{
Expand All @@ -40,7 +40,7 @@ private static IEnumerable<TSource> IntersperseIterator<TSource>(IEnumerable<TSo
isFirst = false;
}

yield return item;
yield return element;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/ExtraLINQ/IEnumerable/JoinedBy.cs
Expand Up @@ -5,7 +5,7 @@ namespace ExtraLinq
public static partial class EnumerableExtensions
{
/// <summary>
/// Concatenates all items of a sequence using the specified separator between each item.
/// Concatenates all elements of a sequence using the specified separator between each element.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="values"/>.</typeparam>
/// <param name="values">A sequence that contains the objects to concatenate.</param>
Expand Down
12 changes: 6 additions & 6 deletions src/app/ExtraLINQ/IEnumerable/Random.cs
Expand Up @@ -31,7 +31,7 @@ public static TSource Random<TSource>(this IEnumerable<TSource> source)
/// <returns>
/// A sequence of distinct random elements from <paramref name="source"/>.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> is null.</exception>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="elementCount"/> is negative or greater than the sequence's element count.
/// </exception>
Expand Down Expand Up @@ -129,14 +129,14 @@ private static IEnumerable<TSource> PickRandomElements<TSource>(IEnumerable<TSou

public static IEnumerable<TSource> ShuffleSequence<TSource>(IEnumerable<TSource> source, Random random)
{
TSource[] items = source.ToArray();
TSource[] elements = source.ToArray();

for (int n = 0; n < items.Length; n++)
for (int n = 0; n < elements.Length; n++)
{
int k = random.Next(n, items.Length);
yield return items[k];
int k = random.Next(n, elements.Length);
yield return elements[k];

items[k] = items[n];
elements[k] = elements[n];
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/app/ExtraLINQ/IEnumerable/Repeat.cs
Expand Up @@ -28,33 +28,33 @@ private static IEnumerable<TSource> RepeatIterator<TSource>(this IEnumerable<TSo

var collection = source as ICollection<TSource>;

var itemBuffer = collection == null
var elementBuffer = collection == null
? new List<TSource>()
: new List<TSource>(collection.Count);

foreach (TSource item in source)
foreach (TSource element in source)
{
yield return item;
yield return element;

// We add this item to a local item buffer so that
// We add this element to a local element buffer so that
// we don't have to enumerate the sequence multiple times
itemBuffer.Add(item);
elementBuffer.Add(element);
}

if (itemBuffer.IsEmpty())
if (elementBuffer.IsEmpty())
{
// If the item buffer is empty, so was the source sequence.
// If the element buffer is empty, so was the source sequence.
// In this case, we can stop here and simply return an empty sequence.
yield break;
}

// We already returned each item of the sequence once,
// so take that into account when returning the items repeatedly
// We already returned each element of the sequence once,
// so take that into account when returning the elements repeatedly
for (int i = 0; i < count - 1; i++)
{
foreach (TSource item in itemBuffer)
foreach (TSource element in elementBuffer)
{
yield return item;
yield return element;
}
}
}
Expand Down

0 comments on commit e00e38d

Please sign in to comment.