-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation for
DistinctUntilChanged
- Loading branch information
1 parent
a359722
commit b006c6d
Showing
6 changed files
with
294 additions
and
29 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Docs/SuperLinq.Docs/apidoc/SuperLinq.SuperEnumerable.DistinctUntilChanged.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
uid: SuperLinq.SuperEnumerable.DistinctUntilChanged``1(System.Collections.Generic.IEnumerable{``0}) | ||
example: [*content] | ||
--- | ||
The following code example demonstrates how to get distinct elements from a sequence using `DistinctUntilChanged`. | ||
[!code-csharp[](SuperLinq/DistinctUntilChanged/DistinctUntilChanged1.linq#L6-)] | ||
|
||
--- | ||
uid: SuperLinq.SuperEnumerable.DistinctUntilChanged``1(System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IEqualityComparer{``0}) | ||
example: [*content] | ||
--- | ||
The following code example demonstrates how to get distinct elements from a sequence using `DistinctUntilChanged`. | ||
[!code-csharp[](SuperLinq/DistinctUntilChanged/DistinctUntilChanged2.linq#L6-)] | ||
|
||
--- | ||
uid: SuperLinq.SuperEnumerable.DistinctUntilChanged``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1}) | ||
example: [*content] | ||
--- | ||
The following code example demonstrates how to get distinct elements from a sequence using `DistinctUntilChanged`. | ||
[!code-csharp[](SuperLinq/DistinctUntilChanged/DistinctUntilChanged3.linq#L6-)] | ||
|
||
--- | ||
uid: SuperLinq.SuperEnumerable.DistinctUntilChanged``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1},System.Collections.Generic.IEqualityComparer{``1}) | ||
example: [*content] | ||
--- | ||
The following code example demonstrates how to get distinct elements from a sequence using `DistinctUntilChanged`. | ||
[!code-csharp[](SuperLinq/DistinctUntilChanged/DistinctUntilChanged4.linq#L6-)] |
52 changes: 52 additions & 0 deletions
52
Docs/SuperLinq.Docs/apidoc/SuperLinq/DistinctUntilChanged/DistinctUntilChanged1.linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<Query Kind="Statements"> | ||
<NuGetReference>SuperLinq</NuGetReference> | ||
<Namespace>SuperLinq</Namespace> | ||
</Query> | ||
|
||
var sequence = new Item[] | ||
{ | ||
new(key: 3, text: "1"), | ||
new(key: 3, text: "2"), | ||
new(key: 2, text: "3"), | ||
new(key: 2, text: "4"), | ||
new(key: 1, text: "5"), | ||
new(key: 1, text: "6"), | ||
new(key: 3, text: "7"), | ||
new(key: 3, text: "8"), | ||
new(key: 2, text: "9"), | ||
new(key: 2, text: "10"), | ||
new(key: 1, text: "11"), | ||
new(key: 1, text: "12"), | ||
}; | ||
|
||
// Get distinct | ||
var result = sequence.DistinctUntilChanged(); | ||
|
||
Console.WriteLine( | ||
"[" + | ||
string.Join(", ", result) + | ||
"]"); | ||
|
||
// This code produces the following output: | ||
// [(3, 1), (2, 3), (1, 5), (3, 7), (2, 9), (1, 11)] | ||
|
||
class Item : IEquatable<Item> | ||
{ | ||
public Item(int key, string text) | ||
{ | ||
Key = key; | ||
Text = text; | ||
} | ||
|
||
public int Key { get; } | ||
public string Text { get; } | ||
|
||
public bool Equals(Item other) => | ||
this.Key == other.Key; | ||
|
||
public override int GetHashCode() => | ||
this.Key.GetHashCode(); | ||
|
||
public override string ToString() => | ||
$"({this.Key}, {this.Text})"; | ||
} |
57 changes: 57 additions & 0 deletions
57
Docs/SuperLinq.Docs/apidoc/SuperLinq/DistinctUntilChanged/DistinctUntilChanged2.linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<Query Kind="Statements"> | ||
<NuGetReference>SuperLinq</NuGetReference> | ||
<Namespace>SuperLinq</Namespace> | ||
</Query> | ||
|
||
var sequence = new Item[] | ||
{ | ||
new(key: 3, text: "1"), | ||
new(key: 3, text: "2"), | ||
new(key: 2, text: "3"), | ||
new(key: 2, text: "4"), | ||
new(key: 1, text: "5"), | ||
new(key: 1, text: "6"), | ||
new(key: 3, text: "7"), | ||
new(key: 3, text: "8"), | ||
new(key: 2, text: "9"), | ||
new(key: 2, text: "10"), | ||
new(key: 1, text: "11"), | ||
new(key: 1, text: "12"), | ||
}; | ||
|
||
// Get distinct | ||
var result = sequence | ||
.DistinctUntilChanged( | ||
new ItemComparer()); | ||
|
||
Console.WriteLine( | ||
"[" + | ||
string.Join(", ", result) + | ||
"]"); | ||
|
||
// This code produces the following output: | ||
// [(3, 1), (2, 3), (1, 5), (3, 7), (2, 9), (1, 11)] | ||
|
||
class Item | ||
{ | ||
public Item(int key, string text) | ||
{ | ||
Key = key; | ||
Text = text; | ||
} | ||
|
||
public int Key { get; } | ||
public string Text { get; } | ||
|
||
public override string ToString() => | ||
$"({this.Key}, {this.Text})"; | ||
} | ||
|
||
class ItemComparer : IEqualityComparer<Item> | ||
{ | ||
public bool Equals(Item x, Item y) => | ||
x.Key == y.Key; | ||
|
||
public int GetHashCode(Item obj) => | ||
obj.Key.GetHashCode(); | ||
} |
32 changes: 32 additions & 0 deletions
32
Docs/SuperLinq.Docs/apidoc/SuperLinq/DistinctUntilChanged/DistinctUntilChanged3.linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Query Kind="Statements"> | ||
<NuGetReference>SuperLinq</NuGetReference> | ||
<Namespace>SuperLinq</Namespace> | ||
</Query> | ||
|
||
var sequence = new[] | ||
{ | ||
(key: 3, text: "1"), | ||
(key: 3, text: "2"), | ||
(key: 2, text: "3"), | ||
(key: 2, text: "4"), | ||
(key: 1, text: "5"), | ||
(key: 1, text: "6"), | ||
(key: 3, text: "7"), | ||
(key: 3, text: "8"), | ||
(key: 2, text: "9"), | ||
(key: 2, text: "10"), | ||
(key: 1, text: "11"), | ||
(key: 1, text: "12"), | ||
}; | ||
|
||
// Get distinct | ||
var result = sequence | ||
.DistinctUntilChanged(x => x.key); | ||
|
||
Console.WriteLine( | ||
"[" + | ||
string.Join(", ", result) + | ||
"]"); | ||
|
||
// This code produces the following output: | ||
// [(3, 1), (2, 3), (1, 5), (3, 7), (2, 9), (1, 11)] |
34 changes: 34 additions & 0 deletions
34
Docs/SuperLinq.Docs/apidoc/SuperLinq/DistinctUntilChanged/DistinctUntilChanged4.linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Query Kind="Statements"> | ||
<NuGetReference>SuperLinq</NuGetReference> | ||
<Namespace>SuperLinq</Namespace> | ||
</Query> | ||
|
||
var sequence = new[] | ||
{ | ||
(key: "aa", text: "1"), | ||
(key: "Aa", text: "2"), | ||
(key: "AA", text: "3"), | ||
(key: "BB", text: "4"), | ||
(key: "bB", text: "5"), | ||
(key: "Cc", text: "6"), | ||
(key: "CC", text: "7"), | ||
(key: "Aa", text: "8"), | ||
(key: "aA", text: "9"), | ||
(key: "bb", text: "10"), | ||
(key: "bB", text: "11"), | ||
(key: "CC", text: "12"), | ||
}; | ||
|
||
// Get distinct | ||
var result = sequence | ||
.DistinctUntilChanged( | ||
x => x.key, | ||
StringComparer.OrdinalIgnoreCase); | ||
|
||
Console.WriteLine( | ||
"[" + | ||
string.Join(", ", result) + | ||
"]"); | ||
|
||
// This code produces the following output: | ||
// [(aa, 1), (BB, 4), (Cc, 6), (Aa, 8), (bb, 10), (CC, 12)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters