TagFirstLastExtensionTagFirstLastTSource, 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.ExtensionsAssembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
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>
- source IEnumerableTSource
- The source sequence.
- resultSelector FuncTSource, Boolean, Boolean, TResult
- A function that determines how to
project the each element along with its first or last tag.
- TSource
- The type of the elements of source.
- TResult
- The type of the element of the returned sequence.
IEnumerableTResult
Returns the resulting sequence.
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).
This operator uses deferred execution and streams its results.
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.