MoreEnumerableSortedMergeTSource Method (IEnumerableTSource, OrderByDirection, IEnumerableTSource) |
Merges two or more sequences that are in a common order (either ascending or descending) into
a single sequence that preserves that order.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 2.7.0
Syntax public static IEnumerable<TSource> SortedMerge<TSource>(
this IEnumerable<TSource> source,
OrderByDirection direction,
params IEnumerable<TSource>[] otherSequences
)
<ExtensionAttribute>
Public Shared Function SortedMerge(Of TSource) (
source As IEnumerable(Of TSource),
direction As OrderByDirection,
ParamArray otherSequences As IEnumerable(Of TSource)()
) As IEnumerable(Of TSource)
public:
[ExtensionAttribute]
generic<typename TSource>
static IEnumerable<TSource>^ SortedMerge(
IEnumerable<TSource>^ source,
OrderByDirection direction,
... array<IEnumerable<TSource>^>^ otherSequences
)
[<ExtensionAttribute>]
static member SortedMerge :
source : IEnumerable<'TSource> *
direction : OrderByDirection *
otherSequences : IEnumerable<'TSource>[] -> IEnumerable<'TSource>
Parameters
- source
- Type: System.Collections.GenericIEnumerableTSource
The primary sequence with which to merge - direction
- Type: MoreLinqOrderByDirection
The ordering that all sequences must already exhibit - otherSequences
- Type: System.Collections.GenericIEnumerableTSource
A variable argument array of zero or more other sequences to merge with
Type Parameters
- TSource
- The type of the elements of the sequence
Return Value
Type:
IEnumerableTSourceA merged, order-preserving sequence containing all of the elements of the original sequences
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
Remarks
Using SortedMerge on sequences that are not ordered or are not in the same order produces
undefined results.
SortedMerge uses performs the merge in a deferred, streaming manner.
Here is an example of a merge, as well as the produced result:
var s1 = new[] { 3, 7, 11 };
var s2 = new[] { 2, 4, 20 };
var s3 = new[] { 17, 19, 25 };
var merged = s1.SortedMerge( OrderByDirection.Ascending, s2, s3 );
var result = merged.ToArray();
See Also