/// <summary> /// Applies an accumulator delegate over a sequence starting with a given seed value, yielding each intermediate result. The <paramref name="seed"/> value is the first element of the source sequence. Each element of the source sequence is only evaluated once. /// </summary> /// <typeparam name="TSource">The type of elements in the source sequence.</typeparam> /// <typeparam name="TResult">The type of elements in the resulting sequence.</typeparam> /// <param name="source">The source sequence.</param> /// <param name="seed">The initial seed value.</param> /// <param name="accumulator">The accumulator delegate. The first parameter passed to the accumulator delegate is the previous intermediate result; the second parameter is the current element of the source sequence.</param> /// <returns>The results of the accumulator delegate.</returns> public static IEnumerable <TResult> Scan <TSource, TResult>(this IEnumerable <TSource> source, TResult seed, Func <TResult, TSource, TResult> accumulator) { IEnumerable <TResult> scan = EnumerableSource.Defer(() => { TResult current = seed; return(source.Select(x => current = accumulator(seed, x))); }); return(EnumerableSource.Return(seed).Concat(scan)); }
/// <summary> /// Converts a single value into a sorted sequence containing a single value. The sequence is treated as though it were sorted by the specified comparison delegate. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="source">The value.</param> /// <param name="comparer">The comparison delegate that defines how the sequence is sorted.</param> /// <returns>A sorted sequence containing a single element, <paramref name="source"/>.</returns> public static ISortedEnumerable <T> Return <T>(T source, Func <T, T, int> comparer) { return(new SortedEnumerableWrapper <T>(EnumerableSource.Return(source), A.Comparer(comparer))); }
/// <summary> /// Converts a single value into a sorted sequence containing a single value. The sequence is treated as though it were sorted by the default comparison object. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="source">The value.</param> /// <returns>A sorted sequence containing a single element, <paramref name="source"/>.</returns> public static ISortedEnumerable <T> Return <T>(T source) { return(new SortedEnumerableWrapper <T>(EnumerableSource.Return(source), Comparer <T> .Default)); }
/// <summary> /// Converts a single value into a sorted sequence containing a single value. The sequence is treated as though it were sorted by the specified comparison object. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="source">The value.</param> /// <param name="comparer">The comparison object that defines how the sequence is sorted.</param> /// <returns>A sorted sequence containing a single element, <paramref name="source"/>.</returns> public static ISortedEnumerable <T> Return <T>(T source, IComparer <T> comparer) { return(new SortedEnumerableWrapper <T>(EnumerableSource.Return(source), comparer)); }