Method TagFirstLast
View SourceTagFirstLast<TSource>(IAsyncEnumerable<TSource>)
Returns a sequence resulting from applying a function to each element in the source sequence with additional parameters indicating whether the element is the first and/or last of the sequence.
Declaration
public static IAsyncEnumerable<(TSource item, bool isFirst, bool isLast)> TagFirstLast<TSource>(this IAsyncEnumerable<TSource> source)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<(TSource item, bool isFirst, bool isLast)> | Returns the resulting sequence. |
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of |
Remarks
This operator uses deferred execution and streams its results.
Examples
var numbers = new[] { 123, 456, 789 };
var result = numbers.TagFirstLast();
The <code>result</code> variable, when iterated over, will yield
<code>(item: 123, isFirst: True, isLast: False)</code>,
<code>(item: 456, isFirst: False, isLast: False)</code> and
<code>(item: 789, isFirst: False, isLast: True)</code> in turn.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TagFirstLast<TSource, TResult>(IAsyncEnumerable<TSource>, Func<TSource, bool, bool, TResult>)
Returns a sequence resulting from applying a function to each element in the source sequence with additional parameters indicating whether the element is the first and/or last of the sequence.
Declaration
public static IAsyncEnumerable<TResult> TagFirstLast<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, bool, bool, TResult> resultSelector)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The source sequence. |
Func<TSource, bool, bool, TResult> | resultSelector | A function that determines how to project the each element along with its first or last tag. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TResult> | Returns the resulting sequence. |
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of |
TResult | The type of the element of the returned sequence. |
Remarks
This operator uses deferred execution and streams its results.
Examples
var numbers = new[] { 123, 456, 789 };
var result = numbers.TagFirstLast((num, fst, lst) => new
{
Number = num,
IsFirst = fst, IsLast = lst
});
The <code>result</code> variable, when iterated over, will yield
<code>{ Number = 123, IsFirst = True, IsLast = False }</code>,
<code>{ Number = 456, IsFirst = False, IsLast = False }</code> and
<code>{ Number = 789, IsFirst = False, IsLast = True }</code> in turn.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|