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 StreamQueryExtensionsInheritance
Section titled “Inheritance”object ← StreamQueryExtensions
Inherited Members
Section titled “Inherited Members”object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Methods
Section titled “Methods”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)Parameters
Section titled “Parameters”sender ISender
query IStreamQuery<TResult>
Returns
Section titled “Returns”ValueTask<Result<List<TResult>>>
Type Parameters
Section titled “Type Parameters”TResult
Remarks
Section titled “Remarks”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)Parameters
Section titled “Parameters”result Result<IAsyncEnumerable<T>>
Returns
Section titled “Returns”Type Parameters
Section titled “Type Parameters”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)Parameters
Section titled “Parameters”result Result<IAsyncEnumerable<TIn>>
mapper Func<TIn, TOut>
Returns
Section titled “Returns”Result<IAsyncEnumerable<TOut>>
Type Parameters
Section titled “Type Parameters”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)Parameters
Section titled “Parameters”result Result<IAsyncEnumerable<T>>
count int
Returns
Section titled “Returns”Type Parameters
Section titled “Type Parameters”T