Skip to content

Commit 518e32b

Browse files
Update documentation for GroupAdjacent
1 parent d25d383 commit 518e32b

File tree

8 files changed

+440
-148
lines changed

8 files changed

+440
-148
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
uid: SuperLinq.SuperEnumerable.GroupAdjacent``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1})
3+
example: [*content]
4+
---
5+
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
6+
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent1.linq#L6-)]
7+
8+
---
9+
uid: SuperLinq.SuperEnumerable.GroupAdjacent``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Collections.Generic.IEqualityComparer{``1})
10+
example: [*content]
11+
---
12+
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
13+
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent2.linq#L6-)]
14+
15+
---
16+
uid: SuperLinq.SuperEnumerable.GroupAdjacent``3(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Func{``0,``2})
17+
example: [*content]
18+
---
19+
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
20+
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent3.linq#L6-)]
21+
22+
---
23+
uid: SuperLinq.SuperEnumerable.GroupAdjacent``3(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Func{``0,``2},System.Collections.Generic.IEqualityComparer{``1})
24+
example: [*content]
25+
---
26+
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
27+
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent4.linq#L6-)]
28+
29+
---
30+
uid: SuperLinq.SuperEnumerable.GroupAdjacent``3(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Func{``1,System.Collections.Generic.IEnumerable{``0},``2})
31+
example: [*content]
32+
---
33+
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
34+
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent5.linq#L6-)]
35+
36+
---
37+
uid: SuperLinq.SuperEnumerable.GroupAdjacent``3(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Func{``1,System.Collections.Generic.IEnumerable{``0},``2},System.Collections.Generic.IEqualityComparer{``1})
38+
example: [*content]
39+
---
40+
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
41+
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent6.linq#L6-)]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = new[]
7+
{
8+
(key: 1, value: 123),
9+
(key: 1, value: 456),
10+
(key: 1, value: 789),
11+
(key: 2, value: 987),
12+
(key: 2, value: 654),
13+
(key: 2, value: 321),
14+
(key: 3, value: 789),
15+
(key: 3, value: 456),
16+
(key: 3, value: 123),
17+
(key: 1, value: 123),
18+
(key: 1, value: 456),
19+
(key: 1, value: 781),
20+
};
21+
22+
// Group adjacent items
23+
var result = sequence
24+
.GroupAdjacent(
25+
x => x.key);
26+
27+
Console.WriteLine(
28+
"[ " +
29+
string.Join(
30+
", ",
31+
result.Select(c => "[" + string.Join(", ", c) + "]")) +
32+
" ]");
33+
34+
// This code produces the following output:
35+
// [ [(1, 123), (1, 456), (1, 789)], [(2, 987), (2, 654), (2, 321)], [(3, 789), (3, 456), (3, 123)], [(1, 123), (1, 456), (1, 781)] ]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = new[]
7+
{
8+
(key: "jan", value: 123),
9+
(key: "Jan", value: 456),
10+
(key: "JAN", value: 789),
11+
(key: "feb", value: 987),
12+
(key: "Feb", value: 654),
13+
(key: "FEB", value: 321),
14+
(key: "mar", value: 789),
15+
(key: "Mar", value: 456),
16+
(key: "MAR", value: 123),
17+
(key: "jan", value: 123),
18+
(key: "Jan", value: 456),
19+
(key: "JAN", value: 781),
20+
};
21+
22+
// Group adjacent items
23+
var result = sequence
24+
.GroupAdjacent(
25+
x => x.key,
26+
StringComparer.OrdinalIgnoreCase);
27+
28+
Console.WriteLine(
29+
"[ " +
30+
string.Join(
31+
", ",
32+
result.Select(c => "[" + string.Join(", ", c) + "]")) +
33+
" ]");
34+
35+
// This code produces the following output:
36+
// [ [(jan, 123), (Jan, 456), (JAN, 789)], [(feb, 987), (Feb, 654), (FEB, 321)], [(mar, 789), (Mar, 456), (MAR, 123)], [(jan, 123), (Jan, 456), (JAN, 781)] ]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = new[]
7+
{
8+
(key: 1, value: 123),
9+
(key: 1, value: 456),
10+
(key: 1, value: 789),
11+
(key: 2, value: 987),
12+
(key: 2, value: 654),
13+
(key: 2, value: 321),
14+
(key: 3, value: 789),
15+
(key: 3, value: 456),
16+
(key: 3, value: 123),
17+
(key: 1, value: 123),
18+
(key: 1, value: 456),
19+
(key: 1, value: 781),
20+
};
21+
22+
// Group adjacent items
23+
var result = sequence
24+
.GroupAdjacent(
25+
x => x.key,
26+
x => x.value);
27+
28+
Console.WriteLine(
29+
"[ " +
30+
string.Join(
31+
", ",
32+
result.Select(c => "[" + string.Join(", ", c) + "]")) +
33+
" ]");
34+
35+
// This code produces the following output:
36+
// [ [(1, 123), (1, 456), (1, 789)], [(2, 987), (2, 654), (2, 321)], [(3, 789), (3, 456), (3, 123)], [(1, 123), (1, 456), (1, 781)] ]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = new[]
7+
{
8+
(key: "jan", value: 123),
9+
(key: "Jan", value: 456),
10+
(key: "JAN", value: 789),
11+
(key: "feb", value: 987),
12+
(key: "Feb", value: 654),
13+
(key: "FEB", value: 321),
14+
(key: "mar", value: 789),
15+
(key: "Mar", value: 456),
16+
(key: "MAR", value: 123),
17+
(key: "jan", value: 123),
18+
(key: "Jan", value: 456),
19+
(key: "JAN", value: 781),
20+
};
21+
22+
// Group adjacent items
23+
var result = sequence
24+
.GroupAdjacent(
25+
x => x.key,
26+
x => x.value,
27+
StringComparer.OrdinalIgnoreCase);
28+
29+
Console.WriteLine(
30+
"[ " +
31+
string.Join(
32+
", ",
33+
result.Select(c => "[" + string.Join(", ", c) + "]")) +
34+
" ]");
35+
36+
// This code produces the following output:
37+
// [ [123, 456, 789], [987, 654, 321], [789, 456, 123], [123, 456, 781] ]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = new[]
7+
{
8+
(key: 1, value: 123),
9+
(key: 1, value: 456),
10+
(key: 1, value: 789),
11+
(key: 2, value: 987),
12+
(key: 2, value: 654),
13+
(key: 2, value: 321),
14+
(key: 3, value: 789),
15+
(key: 3, value: 456),
16+
(key: 3, value: 123),
17+
(key: 1, value: 123),
18+
(key: 1, value: 456),
19+
(key: 1, value: 781),
20+
};
21+
22+
// Group adjacent items
23+
var result = sequence
24+
.GroupAdjacent(
25+
x => x.key,
26+
(k, g) => new { Key = k, Items = "[" + string.Join(", ", g.Select(x => x.value)) + "]", });
27+
28+
Console.WriteLine(
29+
"[ " +
30+
string.Join(
31+
", ",
32+
result) +
33+
" ]");
34+
35+
// This code produces the following output:
36+
// [ { Key = 1, Items = [123, 456, 789] }, { Key = 2, Items = [987, 654, 321] }, { Key = 3, Items = [789, 456, 123] }, { Key = 1, Items = [123, 456, 781] } ]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = new[]
7+
{
8+
(key: "jan", value: 123),
9+
(key: "Jan", value: 456),
10+
(key: "JAN", value: 789),
11+
(key: "feb", value: 987),
12+
(key: "Feb", value: 654),
13+
(key: "FEB", value: 321),
14+
(key: "mar", value: 789),
15+
(key: "Mar", value: 456),
16+
(key: "MAR", value: 123),
17+
(key: "jan", value: 123),
18+
(key: "Jan", value: 456),
19+
(key: "JAN", value: 781),
20+
};
21+
22+
// Group adjacent items
23+
var result = sequence
24+
.GroupAdjacent(
25+
x => x.key,
26+
(k, g) => new { Key = k, Items = "[" + string.Join(", ", g.Select(x => x.value)) + "]", },
27+
StringComparer.OrdinalIgnoreCase);
28+
29+
Console.WriteLine(
30+
"[ " +
31+
string.Join(
32+
", ",
33+
result) +
34+
" ]");
35+
36+
// This code produces the following output:
37+
// [ { Key = jan, Items = [123, 456, 789] }, { Key = feb, Items = [987, 654, 321] }, { Key = mar, Items = [789, 456, 123] }, { Key = jan, Items = [123, 456, 781] } ]

0 commit comments

Comments
 (0)