SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method SortedMergeBy

    | Edit this page

    SortedMergeBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, params IEnumerable<TSource>[])

    Merges two or more sequences that are in a common order according to a key into a single sequence that preserves that order.

    Declaration
    public static IEnumerable<TSource> SortedMergeBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, params IEnumerable<TSource>[] otherSequences)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The primary sequence with which to merge

    Func<TSource, TKey> keySelector

    A key selector function

    IEnumerable<TSource>[] otherSequences

    A variable argument array of zero or more other sequences to merge with

    Returns
    Type Description
    IEnumerable<TSource>

    A merged, order-preserving sequence containing all of the elements of the original sequences

    Type Parameters
    Name Description
    TSource

    The type of the elements of the sequence

    TKey

    The type of the key used to order elements

    Remarks

    Using SortedMergeBy on sequences that are not ordered or are not in the same order produces undefined results.

    This method uses deferred execution and streams its results.

    Examples

    The following code example demonstrates how to merge two or more sequences that are in a common order into a single sequence that preserves that order using SortedMergeBy.

    var s1 = new[] { 11, 7, 3 };
    var s2 = new[] { 20, 4, 2 };
    var s3 = new[] { 25, 19, 17 };
    
    // Execute a sorted merge of multiple sequences into a single sequence
    var result = s1
        .SortedMergeBy(x => -x, s2, s3);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // One possible random output is as follows:
    // [25, 20, 19, 17, 11, 7, 4, 3, 2]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, keySelector or otherSequences is null.

    | Edit this page

    SortedMergeBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IComparer<TKey>?, params IEnumerable<TSource>[])

    Merges two or more sequences that are in a common order according to a key into a single sequence that preserves that order.

    Declaration
    public static IEnumerable<TSource> SortedMergeBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer, params IEnumerable<TSource>[] otherSequences)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The primary sequence with which to merge

    Func<TSource, TKey> keySelector

    A key selector function

    IComparer<TKey> comparer

    An IComparer<T> to compare keys

    IEnumerable<TSource>[] otherSequences

    A variable argument array of zero or more other sequences to merge with

    Returns
    Type Description
    IEnumerable<TSource>

    A merged, order-preserving sequence containing all of the elements of the original sequences

    Type Parameters
    Name Description
    TSource

    The type of the elements of the sequence

    TKey

    The type of the key used to order elements

    Remarks

    Using SortedMergeBy on sequences that are not ordered or are not in the same order produces undefined results.

    This method uses deferred execution and streams its results.

    Examples

    The following code example demonstrates how to merge two or more sequences that are in a common order into a single sequence that preserves that order using SortedMergeBy.

    var s1 = new[] { 11, 7, 3 };
    var s2 = new[] { 20, 4, 2 };
    var s3 = new[] { 25, 19, 17 };
    
    // Execute a sorted merge of multiple sequences into a single sequence
    var result = s1
        .SortedMergeBy(x => -x, Comparer<int>.Default, s2, s3);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // One possible random output is as follows:
    // [25, 20, 19, 17, 11, 7, 4, 3, 2]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, keySelector or otherSequences is null.

    | Edit this page

    SortedMergeBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, OrderByDirection, params IEnumerable<TSource>[])

    Merges two or more sequences that are in a common order (either ascending or descending) according to a key into a single sequence that preserves that order.

    Declaration
    public static IEnumerable<TSource> SortedMergeBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, OrderByDirection direction, params IEnumerable<TSource>[] otherSequences)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The primary sequence with which to merge

    Func<TSource, TKey> keySelector

    A key selector function

    OrderByDirection direction

    A direction in which to order the elements (ascending, descending)

    IEnumerable<TSource>[] otherSequences

    A variable argument array of zero or more other sequences to merge with

    Returns
    Type Description
    IEnumerable<TSource>

    A merged, order-preserving sequence containing all of the elements of the original sequences

    Type Parameters
    Name Description
    TSource

    The type of the elements of the sequence

    TKey

    The type of the key used to order elements

    Remarks

    Using SortedMergeBy on sequences that are not ordered or are not in the same order produces undefined results.

    This method uses deferred execution and streams its results.

    Examples

    The following code example demonstrates how to merge two or more sequences that are in a common order into a single sequence that preserves that order using SortedMergeBy.

    var s1 = new[] { 3, 7, 11 };
    var s2 = new[] { 2, 4, 20 };
    var s3 = new[] { 17, 19, 25 };
    
    // Execute a sorted merge of multiple sequences into a single sequence
    var result = s1
        .SortedMergeBy(x => -x, OrderByDirection.Descending, s2, s3);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // One possible random output is as follows:
    // [2, 3, 4, 7, 11, 17, 19, 20, 25]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, keySelector or otherSequences is null.

    | Edit this page

    SortedMergeBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, OrderByDirection, IComparer<TKey>?, params IEnumerable<TSource>[])

    Merges two or more sequences that are in a common order (either ascending or descending) according to a key into a single sequence that preserves that order.

    Declaration
    public static IEnumerable<TSource> SortedMergeBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, OrderByDirection direction, IComparer<TKey>? comparer, params IEnumerable<TSource>[] otherSequences)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The primary sequence with which to merge

    Func<TSource, TKey> keySelector

    A key selector function

    OrderByDirection direction

    A direction in which to order the elements (ascending, descending)

    IComparer<TKey> comparer

    An IComparer<T> to compare keys

    IEnumerable<TSource>[] otherSequences

    A variable argument array of zero or more other sequences to merge with

    Returns
    Type Description
    IEnumerable<TSource>

    A merged, order-preserving sequence containing all of the elements of the original sequences

    Type Parameters
    Name Description
    TSource

    The type of the elements of the sequence

    TKey

    The type of the key used to order elements

    Remarks

    Using SortedMergeBy on sequences that are not ordered or are not in the same order produces undefined results.

    This method uses deferred execution and streams its results.

    Examples

    The following code example demonstrates how to merge two or more sequences that are in a common order into a single sequence that preserves that order using SortedMergeBy.

    var s1 = new[] { 3, 7, 11 };
    var s2 = new[] { 2, 4, 20 };
    var s3 = new[] { 17, 19, 25 };
    
    // Execute a sorted merge of multiple sequences into a single sequence
    var result = s1
        .SortedMergeBy(
            x => -x, 
            OrderByDirection.Descending, 
            Comparer<int>.Default, 
            s2, s3);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // One possible random output is as follows:
    // [2, 3, 4, 7, 11, 17, 19, 20, 25]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source, keySelector or otherSequences is null.

    © SuperLinq Authors. All rights reserved.