SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method SkipUntil

    SkipUntil<TSource>(IAsyncEnumerable<TSource>, Func<TSource, bool>)

    Skips items from the input sequence until the given predicate returns true when applied to the current source item; that item will be the last skipped.

    Declaration
    public static IAsyncEnumerable<TSource> SkipUntil<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
    Parameters
    Type Name Description
    IAsyncEnumerable<TSource> source

    Source sequence

    Func<TSource, bool> predicate

    Predicate used to determine when to stop yielding results from the source.

    Returns
    Type Description
    IAsyncEnumerable<TSource>

    Items from the source sequence after the predicate first returns true when applied to the item.

    Type Parameters
    Name Description
    TSource

    Type of the source sequence

    Remarks

    SkipUntil differs from Enumerable.SkipWhile in two respects. Firstly, the sense of the predicate is reversed: it is expected that the predicate will return false to start with, and then return true - for example, when trying to find a matching item in a sequence.

    Secondly, SkipUntil skips the element which causes the predicate to return true. For example, in a sequence

           <pre><code class="lang-csharp">{ 1, 2, 3, 4, 5 }</code></pre>
    

    and with a predicate of

           <pre><code class="lang-csharp">x => x == 3</code></pre>
    
           , the result would be 
    
           <pre><code class="lang-csharp">{ 4, 5 }</code></pre>
    
           .
           </p>
           <p>
           SkipUntil is as lazy as possible: it will not iterate over the source sequence
           until it has to, it won't iterate further than it has to, and it won't evaluate
           the predicate until it has to. (This means that an item may be returned which would
           actually cause the predicate to throw an exception if it were evaluated, so long as
           it comes after the first item causing the predicate to return true.)
           </p>
    
    Exceptions
    Type Condition
    ArgumentNullException

    source or predicate is null

    © SuperLinq Authors. All rights reserved.