SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method TagFirstLast

    TagFirstLast<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 source.

    Remarks

    This operator uses deferred execution and streams its results.

    Examples
    var numbers = new[] { 123, 456, 789 };
    var result = numbers.TagFirstLast();

    The result variable, when iterated over, will yield (item: 123, isFirst: True, isLast: False), (item: 456, isFirst: False, isLast: False) and (item: 789, isFirst: False, isLast: True) in turn.

    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    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 source.

    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 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.

    Exceptions
    Type Condition
    ArgumentNullException

    source or resultSelector is null.

    © SuperLinq Authors. All rights reserved.