MoreEnumerableTagFirstLastTSource, TResult Method |
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.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 2.3.0
Syntax public static IEnumerable<TResult> TagFirstLast<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, bool, bool, TResult> resultSelector
)
<ExtensionAttribute>
Public Shared Function TagFirstLast(Of TSource, TResult) (
source As IEnumerable(Of TSource),
resultSelector As Func(Of TSource, Boolean, Boolean, TResult)
) As IEnumerable(Of TResult)
public:
[ExtensionAttribute]
generic<typename TSource, typename TResult>
static IEnumerable<TResult>^ TagFirstLast(
IEnumerable<TSource>^ source,
Func<TSource, bool, bool, TResult>^ resultSelector
)
[<ExtensionAttribute>]
static member TagFirstLast :
source : IEnumerable<'TSource> *
resultSelector : Func<'TSource, bool, bool, 'TResult> -> IEnumerable<'TResult>
Parameters
- source
- Type: System.Collections.GenericIEnumerableTSource
The source sequence. - resultSelector
- Type: SystemFuncTSource, Boolean, Boolean, TResult
A function that determines how to
project the each element along with its first or last tag.
Type Parameters
- TSource
- The type of the elements of source.
- TResult
- The type of the element of the returned sequence.
Return Value
Type:
IEnumerableTResult
Returns the resulting sequence.
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
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
result variable, when iterated over, will yield
{ Number = 123, IsFirst = True, IsLast = False },
{ Number = 456, IsFirst = False, IsLast = False } and
{ Number = 789, IsFirst = False, IsLast = True } in turn.
See Also