Skip to content

Commit 6925828

Browse files
committed
EnumerableExtensions.GroupWhile - remove useless overload
1 parent 6bbb236 commit 6925828

File tree

2 files changed

+1
-58
lines changed

2 files changed

+1
-58
lines changed

Main/src/Collections/Enumerable/EnumerableExtensions.GroupWhile.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,41 +131,6 @@ private static IEnumerable<IGrouping<TKey, TItem>> GroupWhileCore<T, TItem, TKey
131131
#endregion
132132

133133
#region While(true)
134-
/// <summary>Groups items in the sequence while they have same grouping key.</summary>
135-
/// <typeparam name="T">Type of items in sequence</typeparam>
136-
/// <param name="source">The source.</param>
137-
/// <param name="predicate">Gropung predicate.</param>
138-
/// <returns>Grouped items.</returns>
139-
public static IEnumerable<T[]> GroupWhile<T>(
140-
[NotNull] this IEnumerable<T> source,
141-
[NotNull] Func<T, bool> predicate)
142-
{
143-
Code.NotNull(source, nameof(source));
144-
Code.NotNull(predicate, nameof(predicate));
145-
return GroupWhileCore(source, predicate);
146-
}
147-
148-
private static IEnumerable<T[]> GroupWhileCore<T>(
149-
IEnumerable<T> source, Func<T, bool> predicate)
150-
{
151-
var groupingList = new List<T>();
152-
153-
foreach (var item in source)
154-
{
155-
if (groupingList.Count > 0 && !predicate(item))
156-
{
157-
yield return groupingList.ToArray();
158-
groupingList.Clear();
159-
}
160-
groupingList.Add(item);
161-
}
162-
163-
if (groupingList.Count > 0)
164-
{
165-
yield return groupingList.ToArray();
166-
}
167-
}
168-
169134
/// <summary>Groups items in the sequence while they have same grouping key.</summary>
170135
/// <typeparam name="T">Type of items in sequence</typeparam>
171136
/// <param name="source">The source.</param>

Main/tests/Collections/Enumerable/EnumerableExtensionTests.GroupWhile.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,13 @@ public void GroupWhileToString(string input, string expected)
3838

3939
[TestCase("1", 2, "1")]
4040
[TestCase("1,2", 2, "1,2")]
41-
[TestCase("1,2,3,5,8,9,10,123,1,2,3,4", 2, "1,2,3,5|8,9,10|123|1,2,3,4")]
41+
[TestCase("1,2,3,5,8,9,10,123,1,2,3,4,8,12", 2, "1,2,3,5|8,9,10|123|1,2,3,4|8|12")]
4242
public void GroupWhileDelta(string input, int delta, string expected)
4343
{
4444
var data = input.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
4545
var grouping = data.GroupWhile((a, b) => Math.Abs(a - b) <= delta);
4646
var result = grouping.Select(g => g.Join(",")).Join("|");
4747
Assert.AreEqual(result, expected);
4848
}
49-
50-
[TestCase("1", "1")]
51-
[TestCase("1,1", "1,1")]
52-
[TestCase("1,2,3,5,8,9,10,123,1,2,3,4", "1|2,3,5|8,9|10,123,1|2,3|4")]
53-
public void GroupWhileOdd(string input, string expected)
54-
{
55-
var data = input.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
56-
var grouping = data.GroupWhile(a => a % 2 == 1);
57-
var result = grouping.Select(g => g.Join(",")).Join("|");
58-
Assert.AreEqual(result, expected);
59-
}
60-
61-
[TestCase("1", "1")]
62-
[TestCase("1,1", "1,1")]
63-
[TestCase("1,2,3,5,10,11,12,1,2,3,5,6,10", "1,2,3,5|10|11|12,1,2,3,5,6|10")]
64-
public void GroupWhileLess10(string input, string expected)
65-
{
66-
var data = input.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
67-
var grouping = data.GroupWhile(a => a < 10);
68-
var result = grouping.Select(g => g.Join(",")).Join("|");
69-
Assert.AreEqual(result, expected);
70-
}
7149
}
7250
}

0 commit comments

Comments
 (0)