SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method Partition

    Partition<T>(IAsyncEnumerable<T>, Func<T, bool>, CancellationToken)

    Partitions or splits a sequence in two using a predicate.

    Declaration
    public static ValueTask<(IEnumerable<T> True, IEnumerable<T> False)> Partition<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    IAsyncEnumerable<T> source

    The source sequence.

    Func<T, bool> predicate

    The predicate function.

    CancellationToken cancellationToken

    The optional cancellation token to be used for cancelling the sequence at any time.

    Returns
    Type Description
    ValueTask<(IEnumerable<T> True, IEnumerable<T> False)>

    A tuple of elements satisfying the predicate and those that do not, respectively.

    Type Parameters
    Name Description
    T

    Type of source elements.

    Examples
    var (evens, odds) =
        Enumerable.Range(0, 10).Partition(x => x % 2 == 0);

    The evens variable, when iterated over, will yield 0, 2, 4, 6 and then 8. The odds variable, when iterated over, will yield 1, 3, 5, 7 and then 9.

    Exceptions
    Type Condition
    ArgumentNullException

    source is null

    Partition<T, TResult>(IAsyncEnumerable<T>, Func<T, bool>, Func<IEnumerable<T>, IEnumerable<T>, TResult>, CancellationToken)

    Partitions or splits a sequence in two using a predicate and then projects a result from the two.

    Declaration
    public static ValueTask<TResult> Partition<T, TResult>(this IAsyncEnumerable<T> source, Func<T, bool> predicate, Func<IEnumerable<T>, IEnumerable<T>, TResult> resultSelector, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    IAsyncEnumerable<T> source

    The source sequence.

    Func<T, bool> predicate

    The predicate function.

    Func<IEnumerable<T>, IEnumerable<T>, TResult> resultSelector

    Function that projects the result from sequences of elements that satisfy the predicate and those that do not, respectively, passed as arguments.

    CancellationToken cancellationToken

    The optional cancellation token to be used for cancelling the sequence at any time.

    Returns
    Type Description
    ValueTask<TResult>

    The return value from resultSelector.

    Type Parameters
    Name Description
    T

    Type of source elements.

    TResult

    Type of the result.

    Examples
    var (evens, odds) =
        Enumerable.Range(0, 10)
                  .Partition(x => x % 2 == 0, ValueTuple.Create);

    The evens variable, when iterated over, will yield 0, 2, 4, 6 and then 8. The odds variable, when iterated over, will yield 1, 3, 5, 7 and then 9.

    Exceptions
    Type Condition
    ArgumentNullException

    source is null

    ArgumentNullException

    predicate is null

    ArgumentNullException

    resultSelector is null

    © SuperLinq Authors. All rights reserved.