Class MapIfExtensions
- Namespace
- Trellis
- Assembly
- Trellis.Results.dll
Conditionally transforms the value inside a Result when a condition or predicate is met.
public static class MapIfExtensions
- Inheritance
-
MapIfExtensions
- Inherited Members
Methods
MapIf<T>(Result<T>, bool, Func<T, T>)
Transforms the value if the result is successful and the condition is true. Returns the original result unchanged if the condition is false or the result is a failure.
public static Result<T> MapIf<T>(this Result<T> result, bool condition, Func<T, T> func)
Parameters
resultResult<T>The result whose value may be transformed.
conditionboolThe boolean condition that must be true for the transformation to apply.
funcFunc<T, T>The transformation function to apply to the value.
Returns
- Result<T>
A result with the transformed value if successful and condition is true; otherwise the original result.
Type Parameters
TType of the result value.
Exceptions
- ArgumentNullException
Thrown when
funcis null.
MapIf<T>(Result<T>, Func<T, bool>, Func<T, T>)
Transforms the value if the result is successful and the predicate returns true for the value. Returns the original result unchanged if the predicate is false or the result is a failure.
public static Result<T> MapIf<T>(this Result<T> result, Func<T, bool> predicate, Func<T, T> func)
Parameters
resultResult<T>The result whose value may be transformed.
predicateFunc<T, bool>The predicate function to test the value against.
funcFunc<T, T>The transformation function to apply to the value.
Returns
- Result<T>
A result with the transformed value if successful and predicate is true; otherwise the original result.
Type Parameters
TType of the result value.
Exceptions
- ArgumentNullException
Thrown when
predicateorfuncis null.