DifferenceBy - Kalkwst/Risotto GitHub Wiki

Definition

Returns the difference between two sequences, after applying the provided transformer function to each element of both.

In this page

Overloads

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.

DifferenceBy(IEnumerable target, Func<TSource, TResult> fn)

public static IEnumerable<TResult> DifferenceBy<TSource, TResult>(this IEnumerable<TSource> source, IEnumerable<TSource> target, Func<TSource, TResult> fn);

Type Parameters

TSource
The type of the elements of the original sequences.

TResult
The type of elements after the projection of fn.

Parameters

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.

Returns

IEnumerable<TResult>
A sequence containing all of the elements of the difference, after the projection function is applied.

Exceptions

ArgumentNullException
source is null

-or-

target is null

-or-

fn is null

Example

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 ]

DifferenceBy(IEnumerable target, Func<TSource, TResult> fn, EqualityComparer comparer)

Returns the difference between two sequences, after applying the provided transformer function to each element of both, using a provided comparer to determine equality.

Type Parameters

TSource
The type of the elements of the original sequences.

TResult
The type of elements after the projection of fn.

Parameters

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.

comparerIEqualityComparer
An equality comparer to compare values.

Returns

IEnumerable<IEnumerable<TResult>>
A sequence containing all of the elements of the difference, after the projection function is applied.

Exceptions

ArgumentNullException
source is null

-or-

target is null

-or-

fn is null

-or-

comparer is null

Example

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);
⚠️ **GitHub.com Fallback** ⚠️