Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Feb 26, 2024
2 parents 1e5cc48 + 5c1ea9d commit afeb9a9
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 87 deletions.
12 changes: 4 additions & 8 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
* `IEnumerable<KeyValuePair<TKey,TAccumulate>> AggregateBy<TSource, TKey, TAccumulate>(Func<TSource,TKey>, Func<TKey,TAccumulate>, Func<TAccumulate,TSource,TAccumulate>, IEqualityComparer<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.aggregateby?view=net-9.0#system-linq-enumerable-aggregateby-3(system-collections-generic-ienumerable((-0))-system-func((-0-1))-2-system-func((-2-0-2))-system-collections-generic-iequalitycomparer((-1))))
* `IEnumerable<TSource[]> Chunk<TSource>(Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.chunk)
* `IEnumerable<KeyValuePair<TKey,Int32>> CountBy<TSource, TKey>(Func<TSource,TKey>, IEqualityComparer<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.countby)
* `IEnumerable<TSource> Except<TSource>(TSource)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))))
* `IEnumerable<TSource> Except<TSource>(TSource[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))))
* `IEnumerable<TSource> Except<TSource>(TSource, IEqualityComparer<TSource>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0))))
* `IEnumerable<TSource> Except<TSource>(IEqualityComparer<TSource>, TSource[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0))))
* `IEnumerable<ValueTuple<Int32,TSource>> Index<TSource>()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.index#system-linq-enumerable-index-1(system-collections-generic-ienumerable((-0))))
* `TSource MaxBy<TSource, TKey>(Func<TSource,TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.maxby#system-linq-enumerable-maxby-2(system-collections-generic-ienumerable((-0))-system-func((-0-1))))
* `TSource MaxBy<TSource, TKey>(Func<TSource,TKey>, IComparer<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.maxby?view=net-8.0#system-linq-enumerable-maxby-2(system-collections-generic-ienumerable((-0))-system-func((-0-1))-system-collections-generic-icomparer((-1))))
Expand Down Expand Up @@ -316,9 +312,9 @@

#### StringPolyfill

* `String Join(Char, String[])`
* `String Join(Char, Object[])`
* `String Join(Char, String[], Int32, Int32)`
* `String Join<T>(Char, IEnumerable<T>)`
* `String Join(Char, String[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()))
* `String Join(Char, Object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-object()))
* `String Join(Char, String[], Int32, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()-system-int32-system-int32))
* `String Join<T>(Char, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join-1(system-char-system-collections-generic-ienumerable((-0))))


12 changes: 4 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,6 @@ The class `Polyfill` includes the following extension methods:
* `IEnumerable<KeyValuePair<TKey,TAccumulate>> AggregateBy<TSource, TKey, TAccumulate>(Func<TSource,TKey>, Func<TKey,TAccumulate>, Func<TAccumulate,TSource,TAccumulate>, IEqualityComparer<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.aggregateby?view=net-9.0#system-linq-enumerable-aggregateby-3(system-collections-generic-ienumerable((-0))-system-func((-0-1))-2-system-func((-2-0-2))-system-collections-generic-iequalitycomparer((-1))))
* `IEnumerable<TSource[]> Chunk<TSource>(Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.chunk)
* `IEnumerable<KeyValuePair<TKey,Int32>> CountBy<TSource, TKey>(Func<TSource,TKey>, IEqualityComparer<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.countby)
* `IEnumerable<TSource> Except<TSource>(TSource)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))))
* `IEnumerable<TSource> Except<TSource>(TSource[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))))
* `IEnumerable<TSource> Except<TSource>(TSource, IEqualityComparer<TSource>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0))))
* `IEnumerable<TSource> Except<TSource>(IEqualityComparer<TSource>, TSource[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0))))
* `IEnumerable<ValueTuple<Int32,TSource>> Index<TSource>()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.index#system-linq-enumerable-index-1(system-collections-generic-ienumerable((-0))))
* `TSource MaxBy<TSource, TKey>(Func<TSource,TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.maxby#system-linq-enumerable-maxby-2(system-collections-generic-ienumerable((-0))-system-func((-0-1))))
* `TSource MaxBy<TSource, TKey>(Func<TSource,TKey>, IComparer<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.maxby?view=net-8.0#system-linq-enumerable-maxby-2(system-collections-generic-ienumerable((-0))-system-func((-0-1))-system-collections-generic-icomparer((-1))))
Expand Down Expand Up @@ -672,10 +668,10 @@ The class `Polyfill` includes the following extension methods:

#### StringPolyfill

* `String Join(Char, String[])`
* `String Join(Char, Object[])`
* `String Join(Char, String[], Int32, Int32)`
* `String Join<T>(Char, IEnumerable<T>)`
* `String Join(Char, String[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()))
* `String Join(Char, Object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-object()))
* `String Join(Char, String[], Int32, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()-system-int32-system-int32))
* `String Join<T>(Char, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join-1(system-char-system-collections-generic-ienumerable((-0))))

<!-- endInclude -->

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>2.6.5</Version>
<Version>3.0.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Polyfill</PackageTags>
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
Expand Down
128 changes: 64 additions & 64 deletions src/Polyfill/Polyfill_IEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,70 @@

static partial class Polyfill
{
/// <summary>
/// Produces a set items excluding <paramref name="item"/> by using the default equality comparer to compare values.
/// </summary>
/// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
/// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
/// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
/// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0)))")]
public static IEnumerable<TSource> Except<TSource>(
this IEnumerable<TSource> target,
TSource item) =>
Except<TSource>(target, item, null);

/// <summary>
/// Produces the set difference of two sequences by using the default equality comparer to compare values.
/// </summary>
/// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
/// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
/// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
/// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0)))")]
public static IEnumerable<TSource> Except<TSource>(
this IEnumerable<TSource> target,
params TSource[] items) =>
target.Except((IEnumerable<TSource>)items);

/// <summary>
/// Produces a set items excluding <paramref name="item"/> by using <paramref name="comparer"/> to compare values.
/// </summary>
/// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
/// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
/// <param name="comparer">An <see cref="IEqualityComparer&lt;TSource&gt;"/> to compare values.</param>
/// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
/// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0)))")]
public static IEnumerable<TSource> Except<TSource>(
this IEnumerable<TSource> target,
TSource item,
IEqualityComparer<TSource>? comparer)
{
var set = new HashSet<TSource>(comparer);
set.Add(item);
foreach (TSource element in target)
{
if (set.Add(element))
{
yield return element;
}
}
}

/// <summary>
/// Produces the set difference of two sequences by <paramref name="comparer"/> to compare values.
/// </summary>
/// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
/// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
/// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
/// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0)))")]
public static IEnumerable<TSource> Except<TSource>(
this IEnumerable<TSource> target,
IEqualityComparer<TSource> comparer,
params TSource[] items) =>
target.Except((IEnumerable<TSource>)items, comparer);
// /// <summary>
// /// Produces a set items excluding <paramref name="item"/> by using the default equality comparer to compare values.
// /// </summary>
// /// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
// /// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
// /// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
// /// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
// [Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0)))")]
// public static IEnumerable<TSource> Except<TSource>(
// this IEnumerable<TSource> target,
// TSource item) =>
// Except<TSource>(target, item, null);
//
// /// <summary>
// /// Produces the set difference of two sequences by using the default equality comparer to compare values.
// /// </summary>
// /// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
// /// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
// /// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
// /// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
// [Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0)))")]
// public static IEnumerable<TSource> Except<TSource>(
// this IEnumerable<TSource> target,
// params TSource[] items) =>
// target.Except((IEnumerable<TSource>)items);
//
// /// <summary>
// /// Produces a set items excluding <paramref name="item"/> by using <paramref name="comparer"/> to compare values.
// /// </summary>
// /// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
// /// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
// /// <param name="comparer">An <see cref="IEqualityComparer&lt;TSource&gt;"/> to compare values.</param>
// /// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
// /// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
// [Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0)))")]
// public static IEnumerable<TSource> Except<TSource>(
// this IEnumerable<TSource> target,
// TSource item,
// IEqualityComparer<TSource>? comparer)
// {
// var set = new HashSet<TSource>(comparer);
// set.Add(item);
// foreach (TSource element in target)
// {
// if (set.Add(element))
// {
// yield return element;
// }
// }
// }
//
// /// <summary>
// /// Produces the set difference of two sequences by <paramref name="comparer"/> to compare values.
// /// </summary>
// /// <param name="target">An <see cref="IEnumerable&lt;TSource&gt;"/> whose elements that are not equal to <paramref name="item"/> will be returned.</param>
// /// <param name="item">An <see cref="TSource"/> that is elements equal it will cause those elements to be removed from the returned sequence.</param>
// /// <typeparam name="TSource">The type of the elements of <paramref name="target" />.</typeparam>
// /// <returns>A sequence that contains the items of <paramref name="target"/> but excluding <paramref name="item"/>.</returns>
// [Link("https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0)))")]
// public static IEnumerable<TSource> Except<TSource>(
// this IEnumerable<TSource> target,
// IEqualityComparer<TSource> comparer,
// params TSource[] items) =>
// target.Except((IEnumerable<TSource>)items, comparer);

#if !NET9_0_OR_GREATER && FeatureValueTuple

Expand Down
17 changes: 17 additions & 0 deletions src/Polyfill/StringPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Link = System.ComponentModel.DescriptionAttribute;

[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
Expand All @@ -15,6 +16,10 @@
#endif
static partial class StringPolyfill
{
/// <summary>
/// Concatenates an array of strings, using the specified separator between each member.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string())")]
public static string Join(char separator, string[] values)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
Expand All @@ -24,6 +29,10 @@ public static string Join(char separator, string[] values)
#endif
}

/// <summary>
/// Concatenates the string representations of an array of objects, using the specified separator between each member.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-object())")]
public static string Join(char separator, object[] values)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
Expand All @@ -33,6 +42,10 @@ public static string Join(char separator, object[] values)
#endif
}

/// <summary>
/// Concatenates the specified elements of a string array, using the specified separator between each element.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()-system-int32-system-int32)")]
public static string Join(char separator, string?[] value, int startIndex, int count)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
Expand All @@ -42,6 +55,10 @@ public static string Join(char separator, string?[] value, int startIndex, int c
#endif
}

/// <summary>
/// Concatenates the specified elements of a string array, using the specified separator between each element.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join-1(system-char-system-collections-generic-ienumerable((-0)))")]
public static string Join<T>(char separator, IEnumerable<T> values)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
Expand Down
Loading

0 comments on commit afeb9a9

Please sign in to comment.