DifferenceBy - Kalkwst/Risotto GitHub Wiki
Returns the difference between two sequences, after applying the provided transformer function to each element of both.
In this page
- Definition
- Overloads
- DifferenceBy(IEnumerable target, Func<TSource, TResult> fn)
- DifferenceBy(IEnumerable target, Func<TSource, TResult> fn, EqualityComparer comparer)
Overload | Description |
---|---|
DifferenceBy(IEnumerable target, Func<TSource, TResult> fn) | Returns the difference between two sequences, after applying the provided transformer function to each element of both. |
DifferenceBy(IEnumerable target, Func<TSource, TResult> fn, EqualityComparer comparer) | Returns the difference between two sequences by using a specified comparer , after applying the provided transformer function to each element of both. |
public static IEnumerable<TResult> DifferenceBy<TSource, TResult>(this IEnumerable<TSource> source, IEnumerable<TSource> target, Func<TSource, TResult> fn);
TSource
The type of the elements of the original sequences.
TResult
The type of elements after the projection of fn
.
source
IEnumerable <TSource>
The source sequence.
target
IEnumerable <TSource>
The target sequence.
fn
Func <TSource, TResult>
A transform function to apply to each element of the difference.
IEnumerable<TResult>
A sequence containing all of the elements of the difference, after the projection function is applied.
ArgumentNullException
source
is null
-or-
target
is null
-or-
fn
is null
The following code example demonstrates how to use DifferenceBy(IEnumerable target, Func<TSource, TResult> fn) to get the difference between two sequences.
In this example, the difference between two int arrays is calculated, and the elements of the difference are raised to the second power.
int[] array = new int[] { 1, 2, 3, 4, 5 };
int[] array2 = new int[] { 1, 2, 3 };
array.DifferenceBy(array2, (x) => x * x);
//=> [ 16, 25 ]
Returns the difference between two sequences, after applying the provided transformer function to each element of both, using a provided comparer
to determine equality.
TSource
The type of the elements of the original sequences.
TResult
The type of elements after the projection of fn
.
source
IEnumerable <TSource>
The source sequence.
target
IEnumerable <TSource>
The target sequence.
fn
Func <TSource, TResult>
A transform function to apply to each element of the difference.
comparer
IEqualityComparer
An equality comparer to compare values.
IEnumerable<IEnumerable<TResult>>
A sequence containing all of the elements of the difference, after the projection function is applied.
ArgumentNullException
source
is null
-or-
target
is null
-or-
fn
is null
-or-
comparer
is null
The following code example demonstrates how to use DifferenceBy(IEnumerable target, Func<TSource, TResult> fn, EqualityComparer comparer) to get the difference between two sequences.
The different elements are then converted to upper case characters.
var array = new string[]{ "a", "b", "c", "D", "e" };
var array2 = new string[]{ "A", "d", "e" };
array.DifferenceBy(array2, x => x.ToUpper(), StringComparer.OrdinalIgnoreCase);