Class CombineExtensions
- Namespace
- Trellis
- Assembly
- Trellis.Core.dll
Combines two or more Result<TValue> into one tuple containing all the Results.
public static class CombineExtensions
- Inheritance
-
CombineExtensions
- Inherited Members
Examples
// Combine 3 validations
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Bind((email, first, last) => User.Create(email, first, last));
// If any fail, all errors are returned
// If all succeed, User.Create is called with all three values
Remarks
These overloads enable combining results to create tuples of 3-9 elements. All results must succeed for the combined result to succeed. If any result fails, all errors are aggregated into a single combined error.
Key characteristics:
- All validations are executed (no short-circuiting)
- Error.InvalidInput failures are merged into a single Error.InvalidInput
- Mixed error types create a composite failure
- Success returns a tuple containing all values
Use Combine when you need to:
- Validate multiple independent inputs before processing
- Collect all validation errors for user feedback
- Ensure all preconditions are met before proceeding
- Build complex value objects from multiple simple ones
Methods
Combine<T1, T2>(Result<T1>, Result<T2>)
Combine two Result<TValue> into one Tuple containing all the Results.
public static Result<(T1, T2)> Combine<T1, T2>(this Result<T1> t1, Result<T2> t2)
Parameters
Returns
- Result<(T1, T2)>
Tuple containing both the results.
Type Parameters
T1T2
Combine<T1, T2, T3>(Result<(T1, T2)>, Result<T3>)
Combines a 2-element tuple result with another result to create a 3-element tuple.
public static Result<(T1, T2, T3)> Combine<T1, T2, T3>(this Result<(T1, T2)> t1, Result<T3> tc)
Parameters
t1Result<(T1, T2)>The result containing a 2-element tuple.
tcResult<T3>The result to combine as the 3rd element.
Returns
- Result<(T1, T2, T3)>
If both results succeed, returns a success result with a 3-element tuple. If either fails, returns a failure with the combined errors.
Type Parameters
T1The type of element 1 in the resulting tuple.
T2The type of element 2 in the resulting tuple.
T3The type of element 3 in the resulting tuple.
Examples
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Bind((arg1, arg2, arg3) => ProcessData(arg1, arg2, arg3));
Remarks
This is the primary Combine overload for building up tuples incrementally.
Each Combine call adds one more validated value to the tuple. To gate a tuple pipeline on
a no-payload validation, pass a Result<Unit>; the Unit
becomes the next tuple element (use _ in the destructuring lambda to ignore it).
Combine<T1, T2, T3, T4>(Result<(T1, T2, T3)>, Result<T4>)
Combines a 3-element tuple result with another result to create a 4-element tuple.
public static Result<(T1, T2, T3, T4)> Combine<T1, T2, T3, T4>(this Result<(T1, T2, T3)> t1, Result<T4> tc)
Parameters
t1Result<(T1, T2, T3)>The result containing a 3-element tuple.
tcResult<T4>The result to combine as the 4th element.
Returns
- Result<(T1, T2, T3, T4)>
If both results succeed, returns a success result with a 4-element tuple. If either fails, returns a failure with the combined errors.
Type Parameters
T1The type of element 1 in the resulting tuple.
T2The type of element 2 in the resulting tuple.
T3The type of element 3 in the resulting tuple.
T4The type of element 4 in the resulting tuple.
Examples
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Combine(Field4.TryCreate("value4"))
.Bind((arg1, arg2, arg3, arg4) => ProcessData(arg1, arg2, arg3, arg4));
Remarks
This is the primary Combine overload for building up tuples incrementally.
Each Combine call adds one more validated value to the tuple. To gate a tuple pipeline on
a no-payload validation, pass a Result<Unit>; the Unit
becomes the next tuple element (use _ in the destructuring lambda to ignore it).
Combine<T1, T2, T3, T4, T5>(Result<(T1, T2, T3, T4)>, Result<T5>)
Combines a 4-element tuple result with another result to create a 5-element tuple.
public static Result<(T1, T2, T3, T4, T5)> Combine<T1, T2, T3, T4, T5>(this Result<(T1, T2, T3, T4)> t1, Result<T5> tc)
Parameters
t1Result<(T1, T2, T3, T4)>The result containing a 4-element tuple.
tcResult<T5>The result to combine as the 5th element.
Returns
- Result<(T1, T2, T3, T4, T5)>
If both results succeed, returns a success result with a 5-element tuple. If either fails, returns a failure with the combined errors.
Type Parameters
T1The type of element 1 in the resulting tuple.
T2The type of element 2 in the resulting tuple.
T3The type of element 3 in the resulting tuple.
T4The type of element 4 in the resulting tuple.
T5The type of element 5 in the resulting tuple.
Examples
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Combine(Field4.TryCreate("value4"))
.Combine(Field5.TryCreate("value5"))
.Bind((arg1, arg2, arg3, arg4, arg5) => ProcessData(arg1, arg2, arg3, arg4, arg5));
Remarks
This is the primary Combine overload for building up tuples incrementally.
Each Combine call adds one more validated value to the tuple. To gate a tuple pipeline on
a no-payload validation, pass a Result<Unit>; the Unit
becomes the next tuple element (use _ in the destructuring lambda to ignore it).
Combine<T1, T2, T3, T4, T5, T6>(Result<(T1, T2, T3, T4, T5)>, Result<T6>)
Combines a 5-element tuple result with another result to create a 6-element tuple.
public static Result<(T1, T2, T3, T4, T5, T6)> Combine<T1, T2, T3, T4, T5, T6>(this Result<(T1, T2, T3, T4, T5)> t1, Result<T6> tc)
Parameters
t1Result<(T1, T2, T3, T4, T5)>The result containing a 5-element tuple.
tcResult<T6>The result to combine as the 6th element.
Returns
- Result<(T1, T2, T3, T4, T5, T6)>
If both results succeed, returns a success result with a 6-element tuple. If either fails, returns a failure with the combined errors.
Type Parameters
T1The type of element 1 in the resulting tuple.
T2The type of element 2 in the resulting tuple.
T3The type of element 3 in the resulting tuple.
T4The type of element 4 in the resulting tuple.
T5The type of element 5 in the resulting tuple.
T6The type of element 6 in the resulting tuple.
Examples
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Combine(Field4.TryCreate("value4"))
.Combine(Field5.TryCreate("value5"))
.Combine(Field6.TryCreate("value6"))
.Bind((arg1, arg2, arg3, arg4, arg5, arg6) => ProcessData(arg1, arg2, arg3, arg4, arg5, arg6));
Remarks
This is the primary Combine overload for building up tuples incrementally.
Each Combine call adds one more validated value to the tuple. To gate a tuple pipeline on
a no-payload validation, pass a Result<Unit>; the Unit
becomes the next tuple element (use _ in the destructuring lambda to ignore it).
Combine<T1, T2, T3, T4, T5, T6, T7>(Result<(T1, T2, T3, T4, T5, T6)>, Result<T7>)
Combines a 6-element tuple result with another result to create a 7-element tuple.
public static Result<(T1, T2, T3, T4, T5, T6, T7)> Combine<T1, T2, T3, T4, T5, T6, T7>(this Result<(T1, T2, T3, T4, T5, T6)> t1, Result<T7> tc)
Parameters
t1Result<(T1, T2, T3, T4, T5, T6)>The result containing a 6-element tuple.
tcResult<T7>The result to combine as the 7th element.
Returns
- Result<(T1, T2, T3, T4, T5, T6, T7)>
If both results succeed, returns a success result with a 7-element tuple. If either fails, returns a failure with the combined errors.
Type Parameters
T1The type of element 1 in the resulting tuple.
T2The type of element 2 in the resulting tuple.
T3The type of element 3 in the resulting tuple.
T4The type of element 4 in the resulting tuple.
T5The type of element 5 in the resulting tuple.
T6The type of element 6 in the resulting tuple.
T7The type of element 7 in the resulting tuple.
Examples
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Combine(Field4.TryCreate("value4"))
.Combine(Field5.TryCreate("value5"))
.Combine(Field6.TryCreate("value6"))
.Combine(Field7.TryCreate("value7"))
.Bind((arg1, arg2, arg3, arg4, arg5, arg6, arg7) => ProcessData(arg1, arg2, arg3, arg4, arg5, arg6, arg7));
Remarks
This is the primary Combine overload for building up tuples incrementally.
Each Combine call adds one more validated value to the tuple. To gate a tuple pipeline on
a no-payload validation, pass a Result<Unit>; the Unit
becomes the next tuple element (use _ in the destructuring lambda to ignore it).
Combine<T1, T2, T3, T4, T5, T6, T7, T8>(Result<(T1, T2, T3, T4, T5, T6, T7)>, Result<T8>)
Combines a 7-element tuple result with another result to create a 8-element tuple.
public static Result<(T1, T2, T3, T4, T5, T6, T7, T8)> Combine<T1, T2, T3, T4, T5, T6, T7, T8>(this Result<(T1, T2, T3, T4, T5, T6, T7)> t1, Result<T8> tc)
Parameters
t1Result<(T1, T2, T3, T4, T5, T6, T7)>The result containing a 7-element tuple.
tcResult<T8>The result to combine as the 8th element.
Returns
- Result<(T1, T2, T3, T4, T5, T6, T7, T8)>
If both results succeed, returns a success result with a 8-element tuple. If either fails, returns a failure with the combined errors.
Type Parameters
T1The type of element 1 in the resulting tuple.
T2The type of element 2 in the resulting tuple.
T3The type of element 3 in the resulting tuple.
T4The type of element 4 in the resulting tuple.
T5The type of element 5 in the resulting tuple.
T6The type of element 6 in the resulting tuple.
T7The type of element 7 in the resulting tuple.
T8The type of element 8 in the resulting tuple.
Examples
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Combine(Field4.TryCreate("value4"))
.Combine(Field5.TryCreate("value5"))
.Combine(Field6.TryCreate("value6"))
.Combine(Field7.TryCreate("value7"))
.Combine(Field8.TryCreate("value8"))
.Bind((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) => ProcessData(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
Remarks
This is the primary Combine overload for building up tuples incrementally.
Each Combine call adds one more validated value to the tuple. To gate a tuple pipeline on
a no-payload validation, pass a Result<Unit>; the Unit
becomes the next tuple element (use _ in the destructuring lambda to ignore it).
Combine<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Result<(T1, T2, T3, T4, T5, T6, T7, T8)>, Result<T9>)
Combines a 8-element tuple result with another result to create a 9-element tuple.
public static Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> Combine<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this Result<(T1, T2, T3, T4, T5, T6, T7, T8)> t1, Result<T9> tc)
Parameters
t1Result<(T1, T2, T3, T4, T5, T6, T7, T8)>The result containing a 8-element tuple.
tcResult<T9>The result to combine as the 9th element.
Returns
- Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>
If both results succeed, returns a success result with a 9-element tuple. If either fails, returns a failure with the combined errors.
Type Parameters
T1The type of element 1 in the resulting tuple.
T2The type of element 2 in the resulting tuple.
T3The type of element 3 in the resulting tuple.
T4The type of element 4 in the resulting tuple.
T5The type of element 5 in the resulting tuple.
T6The type of element 6 in the resulting tuple.
T7The type of element 7 in the resulting tuple.
T8The type of element 8 in the resulting tuple.
T9The type of element 9 in the resulting tuple.
Examples
var result = EmailAddress.TryCreate(email)
.Combine(FirstName.TryCreate(firstName))
.Combine(LastName.TryCreate(lastName))
.Combine(Field4.TryCreate("value4"))
.Combine(Field5.TryCreate("value5"))
.Combine(Field6.TryCreate("value6"))
.Combine(Field7.TryCreate("value7"))
.Combine(Field8.TryCreate("value8"))
.Combine(Field9.TryCreate("value9"))
.Bind((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) => ProcessData(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9));
Remarks
This is the primary Combine overload for building up tuples incrementally.
Each Combine call adds one more validated value to the tuple. To gate a tuple pipeline on
a no-payload validation, pass a Result<Unit>; the Unit
becomes the next tuple element (use _ in the destructuring lambda to ignore it).