/// <summary> /// Sorts the items on each rail and merges them into a sequential, ordered stream. /// </summary> /// <typeparam name="T">The value type.</typeparam> /// <param name="source">The source IParallelFlowable instance.</param> /// <returns>The new IFlowable instance.</returns> public static IFlowable <T> Sorted <T>(this IParallelFlowable <T> source) { var a = new ParallelFlowableCollect <T, List <T> >(source, ListSupplier <T> .Instance, ListAdd <T> .Instance); var b = new ParallelFlowableMap <List <T>, IList <T> >(a, ListSort <T> .AsFunction); return(new ParallelFlowableSorted <T>(b, Comparer <T> .Default)); }
/// <summary> /// Sorts the items on each rail and merges them into a single, sequential and ordered IList value. /// </summary> /// <typeparam name="T">The value type.</typeparam> /// <param name="source">The source IParallelFlowable instance.</param> /// <returns>The new IFlowable instance.</returns> public static IFlowable <IList <T> > ToSortedList <T>(this IParallelFlowable <T> source) { var a = new ParallelFlowableCollect <T, List <T> >(source, ListSupplier <T> .Instance, ListAdd <T> .Instance); var b = new ParallelFlowableMap <List <T>, IList <T> >(a, ListSort <T> .AsFunction); return(new ParallelFlowableReduceAll <IList <T> >(b, MergeLists <T> .Instance)); }
/// <summary> /// Sorts the items on each rail and merges them into a sequential, ordered stream /// where the item order is determined by the supplied comparer. /// </summary> /// <typeparam name="T">The value type.</typeparam> /// <param name="source">The source IParallelFlowable instance.</param> /// <param name="comparer">The comparer used for sorting and merging.</param> /// <returns>The new IFlowable instance.</returns> public static IFlowable <T> Sorted <T>(this IParallelFlowable <T> source, IComparer <T> comparer) { var a = new ParallelFlowableCollect <T, List <T> >(source, ListSupplier <T> .Instance, ListAdd <T> .Instance); Func <List <T>, IList <T> > f = list => { list.Sort(comparer); return(list); }; var b = new ParallelFlowableMap <List <T>, IList <T> >(a, f); return(new ParallelFlowableSorted <T>(b, Comparer <T> .Default)); }
/// <summary> /// Sorts the items on each rail and merges them into a single, sequential and ordered IList value /// where the ordering is determined by the given comparer. /// </summary> /// <typeparam name="T">The value type.</typeparam> /// <param name="source">The source IParallelFlowable instance.</param> /// <param name="comparer">The shared comparer used for determining the element ordering.</param> /// <returns>The new IFlowable instance.</returns> public static IFlowable <IList <T> > ToSortedList <T>(this IParallelFlowable <T> source, IComparer <T> comparer) { var a = new ParallelFlowableCollect <T, List <T> >(source, ListSupplier <T> .Instance, ListAdd <T> .Instance); Func <List <T>, IList <T> > f = list => { list.Sort(comparer); return(list); }; var b = new ParallelFlowableMap <List <T>, IList <T> >(a, f); return(new ParallelFlowableReduceAll <IList <T> >(b, (u, v) => MergeLists <T> .Merge(u, v, comparer))); }