/// <summary>
        /// Returns consecutive distinct elements by using the specified equality comparer to compare values.
        /// </summary>
        /// <typeparam name="TSource">Source sequence element type.</typeparam>
        /// <param name="source">Source sequence.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare elements.</param>
        public static IEnumerable <TSource> DistinctUntilChanged <TSource>(this IEnumerable <TSource> source, Func <EqualityCompareSource <TSource>, IEqualityComparer <TSource> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TSource>());

            return(source.DistinctUntilChanged(comparer));
        }
示例#2
0
        /// <summary>
        /// Determines whether a sequence contains a specified element by using a specified equality comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
        /// <param name="source">A sequence in which to locate a value.</param>
        /// <param name="value">The value to locate in the sequence.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare values.</param>
        public static bool Contains <TSource>(this IEnumerable <TSource> source, TSource value, Func <EqualityCompareSource <TSource>, IEqualityComparer <TSource> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TSource>());

            return(source.Contains(value, comparer));
        }
        /// <summary>
        /// Returns elements with a distinct key value by using the specified equality comparer to compare key values.
        /// </summary>
        /// <typeparam name="TSource">Source sequence element type.</typeparam>
        /// <typeparam name="TKey">Key type.</typeparam>
        /// <param name="source">Source sequence.</param>
        /// <param name="keySelector">Key selector.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IEnumerable <TSource> Distinct <TSource, TKey>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.Distinct(keySelector, comparer));
        }
示例#4
0
        /// <summary>
        /// Creates a lookup from a sequence according to a specified key selector function, a comparer, and an element selector function.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of the input sequence.</typeparam>
        /// <typeparam name="TKey">The type of the keys returned by the key selector function.</typeparam>
        /// <typeparam name="TElement">The type of the elements returned by the element selector function.</typeparam>
        /// <param name="source">A sequence to create a lookup from.</param>
        /// <param name="keySelector">A function to extract the key for each element.</param>
        /// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static ILookup <TKey, TElement> ToLookup <TSource, TKey, TElement>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.ToLookup(keySelector, elementSelector, comparer));
        }
示例#5
0
        /// <summary>
        /// Produces the set union of two sequences by using a specified equality comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of the input sequences.</typeparam>
        /// <param name="first">A sequence whose distinct elements form the first set for the union.</param>
        /// <param name="second">A sequence whose distinct elements form the second set for the union.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare elements.</param>
        public static IEnumerable <TSource> Union <TSource>(this IEnumerable <TSource> first, IEnumerable <TSource> second, Func <EqualityCompareSource <TSource>, IEqualityComparer <TSource> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TSource>());

            return(first.Union(second, comparer));
        }
示例#6
0
        /// <summary>
        /// Determines whether two sequences are equal by comparing their elements by using a specified equality comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of the input sequences.</typeparam>
        /// <param name="first">A sequence to compare to <paramref name="second"/>.</param>
        /// <param name="second">A sequence to compare to the first sequence.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare elements.</param>
        public static bool SequenceEqual <TSource>(this IEnumerable <TSource> first, IEnumerable <TSource> second, Func <EqualityCompareSource <TSource>, IEqualityComparer <TSource> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TSource>());

            return(first.SequenceEqual(second, comparer));
        }
示例#7
0
        /// <summary>
        /// Creates a dictionary from a sequence according to a specified key selector function and key comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of the input sequence.</typeparam>
        /// <typeparam name="TKey">The type of the keys returned by the key selector function.</typeparam>
        /// <param name="source">A sequence to create a dictionary from.</param>
        /// <param name="keySelector">A function to extract the key for each element.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static Dictionary <TKey, TSource> ToDictionary <TSource, TKey>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.ToDictionary(keySelector, comparer));
        }
示例#8
0
        /// <summary>
        /// Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. Key values are compared by using a specified comparer, and the elements of each group are projected by using a specified function.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of the sequence.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TElement">The type of the elements in the grouping.</typeparam>
        /// <typeparam name="TResult">The type of the result values.</typeparam>
        /// <param name="source">A sequence whose elements are grouped.</param>
        /// <param name="keySelector">A function to extract the key for each element.</param>
        /// <param name="elementSelector">A function to map each source element to an element in the grouping.</param>
        /// <param name="resultSelector">A function to create a result value from each group.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IEnumerable <TResult> GroupBy <TSource, TKey, TElement, TResult>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, Func <TKey, IEnumerable <TElement>, TResult> resultSelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.GroupBy(keySelector, elementSelector, resultSelector, comparer));
        }
示例#9
0
        /// <summary>
        /// Correlates the elements of two sequences based on matching keys. A specified equality comparer is used to compare keys.
        /// </summary>
        /// <typeparam name="TOuter">The type of the elements of the first sequence.</typeparam>
        /// <typeparam name="TInner">The type of the elements of the second sequence.</typeparam>
        /// <typeparam name="TKey">The type of the keys returned by the key selector functions.</typeparam>
        /// <typeparam name="TResult">The type of the result elements.</typeparam>
        /// <param name="outer">The first sequence to join.</param>
        /// <param name="inner">The sequence to join to the first sequence.</param>
        /// <param name="outerKeySelector">A function to extract the join key from each element of the first sequence.</param>
        /// <param name="innerKeySelector">A function to extract the join key from each element of the second sequence.</param>
        /// <param name="resultSelector">A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IEnumerable <TResult> Join <TOuter, TInner, TKey, TResult>(this IEnumerable <TOuter> outer, IEnumerable <TInner> inner, Func <TOuter, TKey> outerKeySelector, Func <TInner, TKey> innerKeySelector, Func <TOuter, TInner, TResult> resultSelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(outer.Join(inner, outerKeySelector, innerKeySelector, resultSelector, comparer));
        }
        /// <summary>
        /// Creates a lookup from an observable sequence according to a specified key selector function, and a comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <typeparam name="TKey">The type of the lookup key computed for each element in the source sequence.</typeparam>
        /// <param name="source">An observable sequence to create a lookup for.</param>
        /// <param name="keySelector">A function to extract a key from each element.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IObservable <ILookup <TKey, TSource> > ToLookup <TSource, TKey>(this IObservable <TSource> source, Func <TSource, TKey> keySelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.ToLookup(keySelector, comparer));
        }
示例#11
0
        /// <summary>
        /// Groups the elements of a sequence according to a specified key selector function and compares the keys by using a specified equality comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of the sequence.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="source">A sequence whose elements are grouped.</param>
        /// <param name="keySelector">A function to extract the key for each element.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IEnumerable <IGrouping <TKey, TSource> > GroupBy <TSource, TKey>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.GroupBy(keySelector, comparer));
        }
        /// <summary>
        /// Creates a dictionary from an observable sequence according to a specified key selector function, a comparer, and an element selector function.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <typeparam name="TKey">The type of the dictionary key computed for each element in the source sequence.</typeparam>
        /// <typeparam name="TElement">The type of the dictionary value computed for each element in the source sequence.</typeparam>
        /// <param name="source">An observable sequence to create a dictionary for.</param>
        /// <param name="keySelector">A function to extract a key from each element.</param>
        /// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IObservable <IDictionary <TKey, TElement> > ToDictionary <TSource, TKey, TElement>(this IObservable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.ToDictionary(keySelector, elementSelector, comparer));
        }
        /// <summary>
        /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function and comparer.
        /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
        /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
        /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
        /// <param name="source">An observable sequence whose elements to group.</param>
        /// <param name="keySelector">A function to extract the key for each element.</param>
        /// <param name="durationSelector">A function to signal the expiration of a group.</param>
        /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IObservable <IGroupedObservable <TKey, TSource> > GroupByUntil <TSource, TKey, TDuration>(this IObservable <TSource> source, Func <TSource, TKey> keySelector, Func <IGroupedObservable <TKey, TSource>, IObservable <TDuration> > durationSelector, int capacity, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.GroupByUntil(keySelector, durationSelector, capacity, comparer));
        }
        /// <summary>
        /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function and comparer and selects the resulting elements by using a specified function.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
        /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
        /// <param name="source">An observable sequence whose elements to group.</param>
        /// <param name="keySelector">A function to extract the key for each element.</param>
        /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
        /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IObservable <IGroupedObservable <TKey, TElement> > GroupBy <TSource, TKey, TElement>(this IObservable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, int capacity, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.GroupBy(keySelector, elementSelector, capacity, comparer));
        }
        /// <summary>
        /// Returns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <typeparam name="TKey">The type of the discriminator key computed for each element in the source sequence.</typeparam>
        /// <param name="source">An observable sequence to retain distinct contiguous elements for, based on a computed key value.</param>
        /// <param name="keySelector">A function to compute the comparison key for each element.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare keys.</param>
        public static IObservable <TSource> DistinctUntilChanged <TSource, TKey>(this IObservable <TSource> source, Func <TSource, TKey> keySelector, Func <EqualityCompareSource <TKey>, IEqualityComparer <TKey> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TKey>());

            return(source.DistinctUntilChanged(keySelector, comparer));
        }
        /// <summary>
        /// Returns an observable sequence that contains only distinct elements according to the comparer.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <param name="source">An observable sequence to retain distinct elements for.</param>
        /// <param name="comparerFactory">The definition of a comparer to compare elements.</param>
        public static IObservable <TSource> Distinct <TSource>(this IObservable <TSource> source, Func <EqualityCompareSource <TSource>, IEqualityComparer <TSource> > comparerFactory)
        {
            var comparer = comparerFactory(EqualityCompareSource.For <TSource>());

            return(source.Distinct(comparer));
        }