|
1 | 1 | using CSharpFunctionalExtensions.Internal; |
2 | 2 | using System; |
3 | | -using System.Collections.Generic; |
4 | 3 | using System.Diagnostics; |
5 | | -using System.Linq; |
6 | 4 | using System.Runtime.Serialization; |
7 | 5 | using System.Threading.Tasks; |
8 | 6 |
|
9 | 7 | namespace CSharpFunctionalExtensions |
10 | 8 | { |
11 | 9 | [Serializable] |
12 | | - public struct Result : IResult, ISerializable |
| 10 | + public partial struct Result : IResult, ISerializable |
13 | 11 | { |
14 | 12 | private static readonly Result OkResult = new Result(false, null); |
15 | 13 |
|
@@ -221,56 +219,6 @@ public static Result FirstFailureOrSuccess(params Result[] results) |
221 | 219 | return Ok(); |
222 | 220 | } |
223 | 221 |
|
224 | | - [DebuggerStepThrough] |
225 | | - public static Result Combine(IEnumerable<Result> results, string errorMessagesSeparator = null) |
226 | | - { |
227 | | - List<Result> failedResults = results.Where(x => x.IsFailure).ToList(); |
228 | | - |
229 | | - if (failedResults.Count == 0) |
230 | | - return Ok(); |
231 | | - |
232 | | - string errorMessage = string.Join(errorMessagesSeparator ?? ErrorMessagesSeparator, failedResults.Select(x => x.Error)); |
233 | | - return Fail(errorMessage); |
234 | | - } |
235 | | - |
236 | | - [DebuggerStepThrough] |
237 | | - public static Result Combine<T>(IEnumerable<Result<T>> results, string errorMessagesSeparator = null) |
238 | | - { |
239 | | - var untyped = results.Select(result => (Result)result); |
240 | | - return Combine(untyped, errorMessagesSeparator); |
241 | | - } |
242 | | - |
243 | | - /// <summary> |
244 | | - /// Combines several results (and any error messages) into a single result. |
245 | | - /// The returned result will be a failure if any of the input <paramref name="results"/> are failures. |
246 | | - /// Error messages are concatenated with the default <see cref="Result.ErrorMessagesSeparator" /> between each message. |
247 | | - /// </summary> |
248 | | - /// <param name="results">The Results to be combined.</param> |
249 | | - /// <returns>A Result that is a success when all the input <paramref name="results"/> are also successes.</returns> |
250 | | - [DebuggerStepThrough] |
251 | | - public static Result Combine(params Result[] results) |
252 | | - => Combine(results, ErrorMessagesSeparator); |
253 | | - |
254 | | - /// <summary> |
255 | | - /// Combines several results (and any error messages) into a single result. |
256 | | - /// The returned result will be a failure if any of the input <paramref name="results"/> are failures. |
257 | | - /// Error messages are concatenated with the specified <paramref name="errorMessagesSeparator"/> between each message. |
258 | | - /// </summary> |
259 | | - /// <param name="errorMessagesSeparator">The string to use as a separator. If omitted, the default <see cref="Result.ErrorMessagesSeparator" /> is used instead.</param> |
260 | | - /// <param name="results">The Results to be combined.</param> |
261 | | - /// <returns>A Result that is a success when all the input <paramref name="results"/> are also successes.</returns> |
262 | | - [DebuggerStepThrough] |
263 | | - public static Result Combine(string errorMessagesSeparator, params Result[] results) |
264 | | - => Combine(results, errorMessagesSeparator); |
265 | | - |
266 | | - [DebuggerStepThrough] |
267 | | - public static Result Combine<T>(params Result<T>[] results) |
268 | | - => Combine(results, ErrorMessagesSeparator); |
269 | | - |
270 | | - [DebuggerStepThrough] |
271 | | - public static Result Combine<T>(string errorMessagesSeparator, params Result<T>[] results) |
272 | | - => Combine(results, errorMessagesSeparator); |
273 | | - |
274 | 222 | private static readonly Func<Exception, string> DefaultTryErrorHandler = exc => exc.Message; |
275 | 223 |
|
276 | 224 | public static Result Try(Action action, Func<Exception, string> errorHandler = null) |
|
0 commit comments