1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 14:08:48 +00:00

Merge branch 'develop' into main

This commit is contained in:
Oliver Booth 2023-04-13 20:55:57 +01:00
commit af6534d23d
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
4 changed files with 56 additions and 2 deletions

View File

@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- X10D: Added math-related extension methods for `BigInteger`. - X10D: Added math-related extension methods for `BigInteger`.
- X10D: Added `Span<T>.Replace(T, T)`. - X10D: Added `Span<T>.Replace(T, T)`.
- X10D: Added `CountDigits` for integer types. - X10D: Added `CountDigits` for integer types.
- X10D: Added `Progress<T>.OnProgressChanged([T])`; - X10D: Added `IEnumerable<T>.Except(T)`.
- X10D: Added `Progress<T>.OnProgressChanged([T])`.
- X10D: Added `TextWriter.WriteNoAlloc(int[, ReadOnlySpan<char>[, IFormatProvider]])`. - X10D: Added `TextWriter.WriteNoAlloc(int[, ReadOnlySpan<char>[, IFormatProvider]])`.
- X10D: Added `TextWriter.WriteNoAlloc(uint[, ReadOnlySpan<char>[, IFormatProvider]])`. - X10D: Added `TextWriter.WriteNoAlloc(uint[, ReadOnlySpan<char>[, IFormatProvider]])`.
- X10D: Added `TextWriter.WriteNoAlloc(long[, ReadOnlySpan<char>[, IFormatProvider]])`. - X10D: Added `TextWriter.WriteNoAlloc(long[, ReadOnlySpan<char>[, IFormatProvider]])`.

View File

@ -37,6 +37,31 @@ public class EnumerableTests
Assert.Throws<ArgumentNullException>(() => source!.ConcatOne("Foobar").ToArray()); Assert.Throws<ArgumentNullException>(() => source!.ConcatOne("Foobar").ToArray());
} }
[Test]
public void Except_ShouldFilterElements_GivenMatchingElements()
{
int[] source = Enumerable.Range(1, 10).ToArray();
int[] result = source.Except(5).ToArray();
Assert.That(result, Is.EquivalentTo(new[] {1, 2, 3, 4, 6, 7, 8, 9, 10}));
}
[Test]
public void Except_ShouldReturnSameElements_GivenNoMatchingElements()
{
int[] source = Enumerable.Range(1, 10).ToArray();
int[] result = source.Except(11).ToArray();
Assert.That(result, Is.EquivalentTo(source));
}
[Test]
public void Except_ShouldThrowArgumentNullException_GivenNullSource()
{
IEnumerable<int> source = null!;
Assert.Throws<ArgumentNullException>(() => source.Except(42));
}
[Test] [Test]
public void MinMax_ShouldReturnCorrectValues_UsingDefaultComparer() public void MinMax_ShouldReturnCorrectValues_UsingDefaultComparer()
{ {

View File

@ -349,7 +349,9 @@ public static class EnumerableExtensions
/// <returns> /// <returns>
/// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that do not satisfy the condition. /// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that do not satisfy the condition.
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> or <paramref name="predicate" /> is null.</exception> /// <exception cref="ArgumentNullException">
/// <paramref name="source" /> or <paramref name="predicate" /> is <see langword="null" />.
/// </exception>
[Pure] [Pure]
public static IEnumerable<TSource> WhereNot<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) public static IEnumerable<TSource> WhereNot<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{ {
@ -381,6 +383,7 @@ public static class EnumerableExtensions
/// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that are not <see langword="null" /> /// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that are not <see langword="null" />
/// (<see langword="Nothing" /> in Visual Basic). /// (<see langword="Nothing" /> in Visual Basic).
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource?> source) public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource?> source)
{ {
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER

View File

@ -39,6 +39,31 @@ public static class EnumerableExtensions
yield return value; yield return value;
} }
/// <summary>
/// Filters a sequence of values by omitting elements that match a specified value.
/// </summary>
/// <param name="source">An <see cref="IEnumerable{T}" /> to filter.</param>
/// <param name="item">The value to omit.</param>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <returns>
/// An <see cref="IEnumerable{T}" /> that contains elements from the input sequence that do not match the specified
/// value.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> source, TSource item)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Where(i => !Equals(i, item));
}
/// <summary> /// <summary>
/// Returns the minimum and maximum values in a sequence of values. /// Returns the minimum and maximum values in a sequence of values.
/// </summary> /// </summary>