8000 Tuple-returning overload for CountDown by Orace · Pull Request #13 · atifaziz/MoreLINQ · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Tuple-returning overload for CountDown #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion MoreLinq/CountDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static partial class MoreEnumerable
/// A function that receives the element and the current countdown
/// value for the element and which returns those mapped to a
/// result returned in the resulting sequence. For elements before
/// the last <paramref name="count"/>, the coundown value is
/// the last <paramref name="count"/>, the countdown value is
/// <c>null</c>.</param>
/// <returns>
/// A sequence of results returned by
Expand Down Expand Up @@ -97,5 +97,31 @@ IEnumerable<TResult> IterateSequence()
yield return resultSelector(queue.Dequeue(), queue.Count);
}
}

/// <summary>
/// Provides a countdown counter for a given count of elements at the
/// tail of the sequence where zero always represents the last element,
/// one represents the second-last element, two represents the
/// third-last element and so on.
/// </summary>
/// <typeparam name="T">
/// The type of elements of <paramref name="source"/></typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="count">Count of tail elements of <paramref name="source"/> to count down.</param>
/// <returns>
/// A sequence of tuple with an element from <paramref name="source"/> and its countdown.
/// For elements before the last <paramref name="count"/>, the countdown value is <c>null</c>.
/// </returns>
/// <remarks>
/// This method uses deferred execution semantics and streams its
/// results. At most, <paramref name="count"/> elements of the source
/// sequence may be buffered at any one time unless
/// <paramref name="source"/> is a collection or a list.
/// </remarks>

public static IEnumerable<(T Item, int? CountDown)> CountDown<T>(this IEnumerable<T> source, int count)
{
return source.CountDown(count, ValueTuple.Create);
}
}
}
26 changes: 25 additions & 1 deletion MoreLinq/Extensions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,30 @@ public static IEnumerable<KeyValuePair<TKey, int>> CountBy<TSource, TKey>(this I
[GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")]
public static partial class CountDownExtension
{

/// <summary>
/// Provides a countdown counter for a given count of elements at the
/// tail of the sequence where zero always represents the last element,
/// one represents the second-last element, two represents the
/// third-last element and so on.
/// </summary>
/// <typeparam name="T">
/// The type of elements of <paramref name="source"/></typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="count">Count of tail elements of <paramref name="source"/> to count down.</param>
/// <returns>
/// A sequence of tuple with an element from <paramref name="source"/> and its countdown.
/// For elements before the last <paramref name="count"/>, the countdown value is <c>null</c>.
/// </returns>
/// <remarks>
/// This method uses deferred execution semantics and streams its
/// results. At most, <paramref name="count"/> elements of the source
/// sequence may be buffered at any one time unless
/// <paramref name="source"/> is a collection or a list.
/// </remarks>

public static IEnumerable<(T Item, int? CountDown)> CountDown<T>(this IEnumerable<T> source, int count)
=> MoreEnumerable.CountDown(source, count);
/// <summary>
/// Provides a countdown counter for a given count of elements at the
/// tail of the sequence where zero always represents the last element,
Expand All @@ -1201,7 +1225,7 @@ public static partial class CountDownExtension
/// A function that receives the element and the current countdown
/// value for the element and which returns those mapped to a
/// result returned in the resulting sequence. For elements before
/// the last <paramref name="count"/>, the coundown value is
/// the last <paramref name="count"/>, the countdown value is
/// <c>null</c>.</param>
/// <returns>
/// A sequence of results returned by
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ Provides a countdown counter for a given count of elements at the tail of the
sequence where zero always represents the last element, one represents the
second-last element, two represents the third-last element and so on.

This method has 2 overloads.

### DistinctBy

Returns all distinct elements of the given source, where "distinctness" is
Expand Down
0