/// <summary> /// Chains two results together by taking the value of the result, and passing it to the /// given function which returns another result. If the result is a failure, then the /// function will not be applied. /// </summary> /// <typeparam name="TNewValue"> /// The type of the result that the value will be mapped to. /// </typeparam> /// <param name="function">The function to apply to the value.</param> /// <returns>A new result with the mapping applied.</returns> public Exceptional <TNewValue> Then <TNewValue>(Func <T, Exceptional <TNewValue> > function) { if (function == null) { throw new ArgumentNullException("function"); } if (IsSuccess) { return(function(Value)); } else { return(Exceptional <TNewValue> .Failure(Exception)); } }
/// <summary> /// Maps the given function to the contents of the result. If the result is a success, the /// function will be applied to the success value; otherwise, the function will not be applied. /// </summary> /// <typeparam name="TNewValue">The type that the success value will be mapped to.</typeparam> /// <param name="function">The function to apply to the success value of the result.</param> /// <returns>A copy of the result with the mapping applied.</returns> public Exceptional <TNewValue> Map <TNewValue>(Func <T, TNewValue> function) { if (function == null) { throw new ArgumentNullException("function"); } if (IsSuccess) { return(Exceptional <TNewValue> .Success(function(Value), PagingInfo)); } else { return(Exceptional <TNewValue> .Failure(Exception)); } }