Skip to content

Commit

Permalink
Update documentation for GroupAdjacent
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Oct 27, 2023
1 parent 5333d6e commit ceabc3d
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
uid: SuperLinq.SuperEnumerable.GroupAdjacent``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1})
example: [*content]
---
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent1.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.GroupAdjacent``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Collections.Generic.IEqualityComparer{``1})
example: [*content]
---
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent2.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.GroupAdjacent``3(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Func{``0,``2})
example: [*content]
---
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent3.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.GroupAdjacent``3(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Func{``0,``2},System.Collections.Generic.IEqualityComparer{``1})
example: [*content]
---
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent4.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.GroupAdjacent``3(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Func{``1,System.Collections.Generic.IEnumerable{``0},``2})
example: [*content]
---
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent5.linq#L6-)]

---
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})
example: [*content]
---
The following code example shows how to group adjacent items in a sequence using `GroupAdjacent`:
[!code-csharp[](SuperLinq/GroupAdjacent/GroupAdjacent6.linq#L6-)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 1, value: 123),
(key: 1, value: 456),
(key: 1, value: 789),
(key: 2, value: 987),
(key: 2, value: 654),
(key: 2, value: 321),
(key: 3, value: 789),
(key: 3, value: 456),
(key: 3, value: 123),
(key: 1, value: 123),
(key: 1, value: 456),
(key: 1, value: 781),
};

// Group adjacent items
var result = sequence
.GroupAdjacent(
x => x.key);

Console.WriteLine(
"[ " +
string.Join(
", ",
result.Select(c => "[" + string.Join(", ", c) + "]")) +
" ]");

// This code produces the following output:
// [ [(1, 123), (1, 456), (1, 789)], [(2, 987), (2, 654), (2, 321)], [(3, 789), (3, 456), (3, 123)], [(1, 123), (1, 456), (1, 781)] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: "jan", value: 123),
(key: "Jan", value: 456),
(key: "JAN", value: 789),
(key: "feb", value: 987),
(key: "Feb", value: 654),
(key: "FEB", value: 321),
(key: "mar", value: 789),
(key: "Mar", value: 456),
(key: "MAR", value: 123),
(key: "jan", value: 123),
(key: "Jan", value: 456),
(key: "JAN", value: 781),
};

// Group adjacent items
var result = sequence
.GroupAdjacent(
x => x.key,
StringComparer.OrdinalIgnoreCase);

Console.WriteLine(
"[ " +
string.Join(
", ",
result.Select(c => "[" + string.Join(", ", c) + "]")) +
" ]");

// This code produces the following output:
// [ [(jan, 123), (Jan, 456), (JAN, 789)], [(feb, 987), (Feb, 654), (FEB, 321)], [(mar, 789), (Mar, 456), (MAR, 123)], [(jan, 123), (Jan, 456), (JAN, 781)] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 1, value: 123),
(key: 1, value: 456),
(key: 1, value: 789),
(key: 2, value: 987),
(key: 2, value: 654),
(key: 2, value: 321),
(key: 3, value: 789),
(key: 3, value: 456),
(key: 3, value: 123),
(key: 1, value: 123),
(key: 1, value: 456),
(key: 1, value: 781),
};

// Group adjacent items
var result = sequence
.GroupAdjacent(
x => x.key,
x => x.value);

Console.WriteLine(
"[ " +
string.Join(
", ",
result.Select(c => "[" + string.Join(", ", c) + "]")) +
" ]");

// This code produces the following output:
// [ [(1, 123), (1, 456), (1, 789)], [(2, 987), (2, 654), (2, 321)], [(3, 789), (3, 456), (3, 123)], [(1, 123), (1, 456), (1, 781)] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: "jan", value: 123),
(key: "Jan", value: 456),
(key: "JAN", value: 789),
(key: "feb", value: 987),
(key: "Feb", value: 654),
(key: "FEB", value: 321),
(key: "mar", value: 789),
(key: "Mar", value: 456),
(key: "MAR", value: 123),
(key: "jan", value: 123),
(key: "Jan", value: 456),
(key: "JAN", value: 781),
};

// Group adjacent items
var result = sequence
.GroupAdjacent(
x => x.key,
x => x.value,
StringComparer.OrdinalIgnoreCase);

Console.WriteLine(
"[ " +
string.Join(
", ",
result.Select(c => "[" + string.Join(", ", c) + "]")) +
" ]");

// This code produces the following output:
// [ [123, 456, 789], [987, 654, 321], [789, 456, 123], [123, 456, 781] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: 1, value: 123),
(key: 1, value: 456),
(key: 1, value: 789),
(key: 2, value: 987),
(key: 2, value: 654),
(key: 2, value: 321),
(key: 3, value: 789),
(key: 3, value: 456),
(key: 3, value: 123),
(key: 1, value: 123),
(key: 1, value: 456),
(key: 1, value: 781),
};

// Group adjacent items
var result = sequence
.GroupAdjacent(
x => x.key,
(k, g) => new { Key = k, Items = "[" + string.Join(", ", g.Select(x => x.value)) + "]", });

Console.WriteLine(
"[ " +
string.Join(
", ",
result) +
" ]");

// This code produces the following output:
// [ { Key = 1, Items = [123, 456, 789] }, { Key = 2, Items = [987, 654, 321] }, { Key = 3, Items = [789, 456, 123] }, { Key = 1, Items = [123, 456, 781] } ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = new[]
{
(key: "jan", value: 123),
(key: "Jan", value: 456),
(key: "JAN", value: 789),
(key: "feb", value: 987),
(key: "Feb", value: 654),
(key: "FEB", value: 321),
(key: "mar", value: 789),
(key: "Mar", value: 456),
(key: "MAR", value: 123),
(key: "jan", value: 123),
(key: "Jan", value: 456),
(key: "JAN", value: 781),
};

// Group adjacent items
var result = sequence
.GroupAdjacent(
x => x.key,
(k, g) => new { Key = k, Items = "[" + string.Join(", ", g.Select(x => x.value)) + "]", },
StringComparer.OrdinalIgnoreCase);

Console.WriteLine(
"[ " +
string.Join(
", ",
result) +
" ]");

// This code produces the following output:
// [ { Key = jan, Items = [123, 456, 789] }, { Key = feb, Items = [987, 654, 321] }, { Key = mar, Items = [789, 456, 123] }, { Key = jan, Items = [123, 456, 781] } ]
Loading

0 comments on commit ceabc3d

Please sign in to comment.