Skip to content

StreamQueryExtensions class

Namespace: Vitreous
Assembly: Vitreous.dll

Extension methods on ISender and Result<T> that make working with stream queries more ergonomic.

public static class StreamQueryExtensions

object ← StreamQueryExtensions

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

CollectStream<TResult>(ISender, IStreamQuery<TResult>, CancellationToken)

Section titled “ CollectStream<TResult>(ISender, IStreamQuery<TResult>, CancellationToken)”

Opens the stream query and eagerly collects all items into a List<T>, returning the collected list wrapped in a Result<T>.

public static ValueTask<Result<List<TResult>>> CollectStream<TResult>(this ISender sender, IStreamQuery<TResult> query, CancellationToken ct = default)

sender ISender

query IStreamQuery<TResult>

ct CancellationToken

ValueTask<Result<List<TResult>>>

TResult

Handles both setup failures (returned by the handler before any item is produced) and mid-stream exceptions (wrapped in an Internal failure). Cancellation is not a failure: an OperationCanceledException propagates. Useful for tests and one-shot scenarios where the full result is needed at once.

FilterStream<T>(Result<IAsyncEnumerable<T>>, Func<T, bool>)

Section titled “ FilterStream<T>(Result<IAsyncEnumerable<T>>, Func<T, bool>)”

Keeps only items in the stream that satisfy predicate. If the result is a failure, the failure passes through untouched. Equivalent to LINQ Where — lazy, no buffering.

public static Result<IAsyncEnumerable<T>> FilterStream<T>(this Result<IAsyncEnumerable<T>> result, Func<T, bool> predicate)

result Result<IAsyncEnumerable<T>>

predicate Func<T, bool>

Result<IAsyncEnumerable<T>>

T

MapStream<TIn, TOut>(Result<IAsyncEnumerable<TIn>>, Func<TIn, TOut>)

Section titled “ MapStream<TIn, TOut>(Result<IAsyncEnumerable<TIn>>, Func<TIn, TOut>)”

Projects each item in the stream using mapper. If the result is a failure, the failure passes through untouched. Equivalent to LINQ Select — lazy, no buffering.

public static Result<IAsyncEnumerable<TOut>> MapStream<TIn, TOut>(this Result<IAsyncEnumerable<TIn>> result, Func<TIn, TOut> mapper)

result Result<IAsyncEnumerable<TIn>>

mapper Func<TIn, TOut>

Result<IAsyncEnumerable<TOut>>

TIn

TOut

TakeStream<T>(Result<IAsyncEnumerable<T>>, int)

Section titled “ TakeStream<T>(Result<IAsyncEnumerable<T>>, int)”

Stops the stream after at most count items. If the result is a failure, the failure passes through untouched. Equivalent to LINQ Take — lazy, no buffering.

public static Result<IAsyncEnumerable<T>> TakeStream<T>(this Result<IAsyncEnumerable<T>> result, int count)

result Result<IAsyncEnumerable<T>>

count int

Result<IAsyncEnumerable<T>>

T