Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Consume/Consume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,13 @@ void IEnumerable_Methods()
#endif
var takeLast = enumerable.TakeLast(3);
var unionBy = enumerable.UnionBy(["c"], _ => _, comparer: default);
var order = enumerable.Order();
var orderComparer = enumerable.Order(StringComparer.Ordinal);
var orderDescending = enumerable.OrderDescending();
var orderDescendingComparer = enumerable.OrderDescending(StringComparer.Ordinal);
IEnumerable<int> lengths = [1];
var intersectBy = enumerable.IntersectBy(lengths, _ => _.Length);
var intersectByComparer = enumerable.IntersectBy(lengths, _ => _.Length, EqualityComparer<int>.Default);
}

void IList_Methods()
Expand Down
38 changes: 38 additions & 0 deletions src/Polyfill/Polyfill_IEnumerable_IntersectBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#if !NET6_0_OR_GREATER

namespace Polyfills;

using System;
using System.Collections.Generic;

static partial class Polyfill
{
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.intersectby?view=net-11.0#system-linq-enumerable-intersectby-2(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-1))-system-func((-0-1)))
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) =>
IntersectBy(first, second, keySelector, null);

/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.intersectby?view=net-11.0#system-linq-enumerable-intersectby-2(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-1))-system-func((-0-1))-system-collections-generic-iequalitycomparer((-1)))
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
IntersectByIterator(first, second, keySelector, comparer);

static IEnumerable<TSource> IntersectByIterator<TSource, TKey>(IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
var set = new HashSet<TKey>(second, comparer);

foreach (var element in first)
{
if (set.Remove(keySelector(element)))
{
yield return element;
}
}
}
}

#endif
32 changes: 32 additions & 0 deletions src/Polyfill/Polyfill_IEnumerable_Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#if !NET7_0_OR_GREATER

namespace Polyfills;

using System;
using System.Collections.Generic;
using System.Linq;

static partial class Polyfill
{
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.order?view=net-11.0#system-linq-enumerable-order-1(system-collections-generic-ienumerable((-0)))
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) =>
source.OrderBy(static item => item);

/// <summary>Sorts the elements of a sequence in ascending order.</summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.order?view=net-11.0#system-linq-enumerable-order-1(system-collections-generic-ienumerable((-0))-system-collections-generic-icomparer((-0)))
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderBy(static item => item, comparer);

/// <summary>Sorts the elements of a sequence in descending order.</summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderdescending?view=net-11.0#system-linq-enumerable-orderdescending-1(system-collections-generic-ienumerable((-0)))
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source) =>
source.OrderByDescending(static item => item);

/// <summary>Sorts the elements of a sequence in descending order.</summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderdescending?view=net-11.0#system-linq-enumerable-orderdescending-1(system-collections-generic-ienumerable((-0))-system-collections-generic-icomparer((-0)))
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderByDescending(static item => item, comparer);
}

#endif
29 changes: 29 additions & 0 deletions src/Split/net461/Polyfill_IEnumerable_IntersectBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
static partial class Polyfill
{
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) =>
IntersectBy(first, second, keySelector, null);
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
IntersectByIterator(first, second, keySelector, comparer);
static IEnumerable<TSource> IntersectByIterator<TSource, TKey>(IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
var set = new HashSet<TKey>(second, comparer);
foreach (var element in first)
{
if (set.Remove(keySelector(element)))
{
yield return element;
}
}
}
}
21 changes: 21 additions & 0 deletions src/Split/net461/Polyfill_IEnumerable_Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
using System.Linq;
static partial class Polyfill
{
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) =>
source.OrderBy(static item => item);
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderBy(static item => item, comparer);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source) =>
source.OrderByDescending(static item => item);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderByDescending(static item => item, comparer);
}
29 changes: 29 additions & 0 deletions src/Split/net462/Polyfill_IEnumerable_IntersectBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
static partial class Polyfill
{
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) =>
IntersectBy(first, second, keySelector, null);
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
IntersectByIterator(first, second, keySelector, comparer);
static IEnumerable<TSource> IntersectByIterator<TSource, TKey>(IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
var set = new HashSet<TKey>(second, comparer);
foreach (var element in first)
{
if (set.Remove(keySelector(element)))
{
yield return element;
}
}
}
}
21 changes: 21 additions & 0 deletions src/Split/net462/Polyfill_IEnumerable_Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
using System.Linq;
static partial class Polyfill
{
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) =>
source.OrderBy(static item => item);
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderBy(static item => item, comparer);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source) =>
source.OrderByDescending(static item => item);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderByDescending(static item => item, comparer);
}
29 changes: 29 additions & 0 deletions src/Split/net47/Polyfill_IEnumerable_IntersectBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
static partial class Polyfill
{
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) =>
IntersectBy(first, second, keySelector, null);
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
IntersectByIterator(first, second, keySelector, comparer);
static IEnumerable<TSource> IntersectByIterator<TSource, TKey>(IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
var set = new HashSet<TKey>(second, comparer);
foreach (var element in first)
{
if (set.Remove(keySelector(element)))
{
yield return element;
}
}
}
}
21 changes: 21 additions & 0 deletions src/Split/net47/Polyfill_IEnumerable_Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
using System.Linq;
static partial class Polyfill
{
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) =>
source.OrderBy(static item => item);
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderBy(static item => item, comparer);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source) =>
source.OrderByDescending(static item => item);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderByDescending(static item => item, comparer);
}
29 changes: 29 additions & 0 deletions src/Split/net471/Polyfill_IEnumerable_IntersectBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
static partial class Polyfill
{
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) =>
IntersectBy(first, second, keySelector, null);
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
IntersectByIterator(first, second, keySelector, comparer);
static IEnumerable<TSource> IntersectByIterator<TSource, TKey>(IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
var set = new HashSet<TKey>(second, comparer);
foreach (var element in first)
{
if (set.Remove(keySelector(element)))
{
yield return element;
}
}
}
}
21 changes: 21 additions & 0 deletions src/Split/net471/Polyfill_IEnumerable_Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
using System.Linq;
static partial class Polyfill
{
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) =>
source.OrderBy(static item => item);
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderBy(static item => item, comparer);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source) =>
source.OrderByDescending(static item => item);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderByDescending(static item => item, comparer);
}
29 changes: 29 additions & 0 deletions src/Split/net472/Polyfill_IEnumerable_IntersectBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
static partial class Polyfill
{
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) =>
IntersectBy(first, second, keySelector, null);
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
IntersectByIterator(first, second, keySelector, comparer);
static IEnumerable<TSource> IntersectByIterator<TSource, TKey>(IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
var set = new HashSet<TKey>(second, comparer);
foreach (var element in first)
{
if (set.Remove(keySelector(element)))
{
yield return element;
}
}
}
}
21 changes: 21 additions & 0 deletions src/Split/net472/Polyfill_IEnumerable_Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
using System.Linq;
static partial class Polyfill
{
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) =>
source.OrderBy(static item => item);
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderBy(static item => item, comparer);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source) =>
source.OrderByDescending(static item => item);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderByDescending(static item => item, comparer);
}
29 changes: 29 additions & 0 deletions src/Split/net48/Polyfill_IEnumerable_IntersectBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
static partial class Polyfill
{
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) =>
IntersectBy(first, second, keySelector, null);
/// <summary>
/// Produces the set intersection of two sequences according to a specified key selector function.
/// </summary>
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer) =>
IntersectByIterator(first, second, keySelector, comparer);
static IEnumerable<TSource> IntersectByIterator<TSource, TKey>(IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
var set = new HashSet<TKey>(second, comparer);
foreach (var element in first)
{
if (set.Remove(keySelector(element)))
{
yield return element;
}
}
}
}
21 changes: 21 additions & 0 deletions src/Split/net48/Polyfill_IEnumerable_Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <auto-generated />
#pragma warning disable
namespace Polyfills;
using System;
using System.Collections.Generic;
using System.Linq;
static partial class Polyfill
{
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) =>
source.OrderBy(static item => item);
/// <summary>Sorts the elements of a sequence in ascending order.</summary>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderBy(static item => item, comparer);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source) =>
source.OrderByDescending(static item => item);
/// <summary>Sorts the elements of a sequence in descending order.</summary>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source, IComparer<T>? comparer) =>
source.OrderByDescending(static item => item, comparer);
}
Loading