Class TraverseAllExtensions
- Namespace
- Trellis
- Assembly
- Trellis.Core.dll
Accumulating-error counterpart to Traverse<TIn, TOut>(IEnumerable<TIn>, Func<TIn, Result<TOut>>). Runs the selector over every item (no short-circuit) and folds failures via the existing Combine(Error?, Error) extension. Useful for form-style validation where every error matters, not just the first one encountered.
public static class TraverseAllExtensions
- Inheritance
-
TraverseAllExtensions
- Inherited Members
Methods
TraverseAllAsync<TIn>(IEnumerable<TIn>, Func<TIn, int, CancellationToken, Task<Result<Unit>>>, CancellationToken)
Sequentially invokes a no-payload selector with each item's zero-based source index and cancellation token, accumulating all failures.
public static Task<Result<Unit>> TraverseAllAsync<TIn>(this IEnumerable<TIn> source, Func<TIn, int, CancellationToken, Task<Result<Unit>>> selector, CancellationToken cancellationToken = default)
Parameters
sourceIEnumerable<TIn>Source collection to enumerate once.
selectorFunc<TIn, int, CancellationToken, Task<Result<Unit>>>Async no-payload selector receiving the item, original zero-based index, and cancellation token.
cancellationTokenCancellationTokenToken checked before each selector invocation and forwarded to the selector.
Returns
Type Parameters
TInType of input items.
Remarks
Indices advance for every item, including failures. Exceptions and cancellation propagate through the returned task, abandoning accumulated state. The token argument is optional; the selector always takes three parameters to avoid ambiguity with unindexed token-aware selectors.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.- OperationCanceledException
Thrown when cancellation is observed.
- OverflowException
Thrown before invoking the selector for an index greater than MaxValue.
TraverseAllAsync<TIn>(IEnumerable<TIn>, Func<TIn, CancellationToken, Task<Result<Unit>>>, CancellationToken)
Asynchronously transforms a collection of items using a no-payload Result<Unit>
selector with cancellation support, accumulating failures via
Combine(Error?, Error). Mirrors
TraverseAsync<TIn>(IEnumerable<TIn>, Func<TIn, CancellationToken, Task<Result<Unit>>>, CancellationToken).
public static Task<Result<Unit>> TraverseAllAsync<TIn>(this IEnumerable<TIn> source, Func<TIn, CancellationToken, Task<Result<Unit>>> selector, CancellationToken cancellationToken = default)
Parameters
sourceIEnumerable<TIn>Source collection to transform.
selectorFunc<TIn, CancellationToken, Task<Result<Unit>>>Async no-payload selector with cancellation support.
cancellationTokenCancellationTokenCancellation token to observe. Cancellation throws OperationCanceledException and abandons accumulated state.
Returns
- Task<Result<Unit>>
Task producing success if all items succeed; otherwise a failure carrying the combined error.
Type Parameters
TInType of input items.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.- OperationCanceledException
Thrown when
cancellationTokenis canceled.
TraverseAllAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, int, CancellationToken, Task<Result<TOut>>>, CancellationToken)
Sequentially transforms every item with its zero-based source index and cancellation token, accumulating all failures.
public static Task<Result<IReadOnlyList<TOut>>> TraverseAllAsync<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, int, CancellationToken, Task<Result<TOut>>> selector, CancellationToken cancellationToken = default)
Parameters
sourceIEnumerable<TIn>Source collection to enumerate once.
selectorFunc<TIn, int, CancellationToken, Task<Result<TOut>>>Async transformation receiving the item, original zero-based index, and cancellation token.
cancellationTokenCancellationTokenToken checked before each selector invocation and forwarded to the selector.
Returns
- Task<Result<IReadOnlyList<TOut>>>
A task containing every transformed value in source order, or the combined failure.
Type Parameters
TInType of input items.
TOutType of output items.
Remarks
Indices advance for every item, including failures. Exceptions and cancellation propagate through the returned task, abandoning accumulated state. The token argument is optional; the selector always takes three parameters to avoid ambiguity with unindexed token-aware selectors. Inline async lambdas prefer this Task overload over the ValueTask overload.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.- OperationCanceledException
Thrown when cancellation is observed.
- OverflowException
Thrown before invoking the selector for an index greater than MaxValue.
TraverseAllAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, int, CancellationToken, ValueTask<Result<TOut>>>, CancellationToken)
Sequentially transforms every item using a ValueTask selector with its zero-based source index and cancellation token, accumulating all failures.
public static ValueTask<Result<IReadOnlyList<TOut>>> TraverseAllAsync<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, int, CancellationToken, ValueTask<Result<TOut>>> selector, CancellationToken cancellationToken = default)
Parameters
sourceIEnumerable<TIn>Source collection to enumerate once.
selectorFunc<TIn, int, CancellationToken, ValueTask<Result<TOut>>>Async transformation receiving the item, original zero-based index, and cancellation token.
cancellationTokenCancellationTokenToken checked before each selector invocation and forwarded to the selector.
Returns
- ValueTask<Result<IReadOnlyList<TOut>>>
A ValueTask containing every transformed value in source order, or the combined failure.
Type Parameters
TInType of input items.
TOutType of output items.
Remarks
Indices advance for every item, including failures. Exceptions and cancellation propagate through the returned ValueTask, abandoning accumulated state. The token argument is optional; the selector always takes three parameters to avoid ambiguity with unindexed token-aware selectors.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.- OperationCanceledException
Thrown when cancellation is observed.
- OverflowException
Thrown before invoking the selector for an index greater than MaxValue.
TraverseAllAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, CancellationToken, Task<Result<TOut>>>, CancellationToken)
Asynchronously transforms a collection of items, accumulating failures via Combine(Error?, Error). Supports cancellation. Mirrors TraverseAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, CancellationToken, Task<Result<TOut>>>, CancellationToken).
public static Task<Result<IReadOnlyList<TOut>>> TraverseAllAsync<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, CancellationToken, Task<Result<TOut>>> selector, CancellationToken cancellationToken = default)
Parameters
sourceIEnumerable<TIn>Source collection to transform.
selectorFunc<TIn, CancellationToken, Task<Result<TOut>>>Async transformation function with cancellation support.
cancellationTokenCancellationTokenCancellation token to observe. Cancellation throws OperationCanceledException and abandons accumulated state.
Returns
- Task<Result<IReadOnlyList<TOut>>>
Task producing success with every transformed value if all items succeed; otherwise a failure carrying the combined error.
Type Parameters
TInType of input items.
TOutType of output items.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.- OperationCanceledException
Thrown when
cancellationTokenis canceled.
TraverseAllAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, CancellationToken, ValueTask<Result<TOut>>>, CancellationToken)
Asynchronously transforms a collection of items using ValueTask<TResult> with cancellation support, accumulating failures via Combine(Error?, Error). Mirrors TraverseAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, CancellationToken, ValueTask<Result<TOut>>>, CancellationToken).
public static ValueTask<Result<IReadOnlyList<TOut>>> TraverseAllAsync<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, CancellationToken, ValueTask<Result<TOut>>> selector, CancellationToken cancellationToken = default)
Parameters
sourceIEnumerable<TIn>Source collection to transform.
selectorFunc<TIn, CancellationToken, ValueTask<Result<TOut>>>Async transformation function with cancellation support.
cancellationTokenCancellationTokenCancellation token to observe. Cancellation throws OperationCanceledException and abandons accumulated state.
Returns
- ValueTask<Result<IReadOnlyList<TOut>>>
ValueTask producing success with every transformed value if all items succeed; otherwise a failure carrying the combined error.
Type Parameters
TInType of input items.
TOutType of output items.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.- OperationCanceledException
Thrown when
cancellationTokenis canceled.
TraverseAllAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, Task<Result<TOut>>>)
Asynchronously transforms a collection of items into a Result containing all transformed items, accumulating failures via Combine(Error?, Error). Selectors are awaited sequentially (mirroring TraverseAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, Task<Result<TOut>>>)).
public static Task<Result<IReadOnlyList<TOut>>> TraverseAllAsync<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, Task<Result<TOut>>> selector)
Parameters
sourceIEnumerable<TIn>Source collection to transform.
selectorFunc<TIn, Task<Result<TOut>>>Async transformation function returning a Result.
Returns
- Task<Result<IReadOnlyList<TOut>>>
Task producing success with every transformed value if all items succeed; otherwise a failure carrying the combined error.
Type Parameters
TInType of input items.
TOutType of output items.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.
TraverseAllAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, ValueTask<Result<TOut>>>)
Asynchronously transforms a collection of items using ValueTask<TResult>, accumulating failures via Combine(Error?, Error). Mirrors TraverseAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, ValueTask<Result<TOut>>>).
public static ValueTask<Result<IReadOnlyList<TOut>>> TraverseAllAsync<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, ValueTask<Result<TOut>>> selector)
Parameters
sourceIEnumerable<TIn>Source collection to transform.
selectorFunc<TIn, ValueTask<Result<TOut>>>Async transformation function returning a Result.
Returns
- ValueTask<Result<IReadOnlyList<TOut>>>
ValueTask producing success with every transformed value if all items succeed; otherwise a failure carrying the combined error.
Type Parameters
TInType of input items.
TOutType of output items.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.
TraverseAll<TIn, TOut>(IEnumerable<TIn>, Func<TIn, int, Result<TOut>>)
Transforms every item with its zero-based source index, accumulating all failures.
public static Result<IReadOnlyList<TOut>> TraverseAll<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, int, Result<TOut>> selector)
Parameters
sourceIEnumerable<TIn>Source collection to enumerate once.
selectorFunc<TIn, int, Result<TOut>>Transformation receiving the item and its original zero-based index.
Returns
- Result<IReadOnlyList<TOut>>
Success with every transformed value in source order, or the combined failure. A single error is preserved; persist-on-failure intent is accumulated.
Type Parameters
TInType of input items.
TOutType of output items.
Remarks
Indices advance for every item, including failures. Selector and enumeration exceptions propagate. The unindexed overload has higher overload-resolution priority to preserve null-literal calls.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.- OverflowException
Thrown before invoking the selector for an index greater than MaxValue.
TraverseAll<TIn, TOut>(IEnumerable<TIn>, Func<TIn, Result<TOut>>)
Transforms a collection of items into a Result containing all transformed items, accumulating any failures via Combine(Error?, Error). Unlike Traverse<TIn, TOut>(IEnumerable<TIn>, Func<TIn, Result<TOut>>), this method does not short-circuit: the selector is invoked for every item.
public static Result<IReadOnlyList<TOut>> TraverseAll<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, Result<TOut>> selector)
Parameters
sourceIEnumerable<TIn>Source collection to transform.
selectorFunc<TIn, Result<TOut>>Transformation function returning a Result.
Returns
- Result<IReadOnlyList<TOut>>
Success carrying every transformed value in source order if every item succeeds; otherwise a failure carrying the combined error. A single failure is returned unchanged (no Error.Aggregate wrap).
Type Parameters
TInType of input items.
TOutType of output items.
Exceptions
- ArgumentNullException
Thrown when
sourceorselectoris null.