@@ -10,6 +10,44 @@ namespace AStar.Dev.Functional.Extensions;
1010[ SuppressMessage ( "ReSharper" , "GrammarMistakeInComment" ) ]
1111public static class ResultExtensions
1212{
13+ /// <summary>
14+ ///
15+ /// </summary>
16+ /// <typeparam name="TSuccess"></typeparam>
17+ /// <typeparam name="TError"></typeparam>
18+ /// <typeparam name="TResult"></typeparam>
19+ /// <param name="resultTask"></param>
20+ /// <param name="onSuccess"></param>
21+ /// <param name="onFailure"></param>
22+ /// <returns></returns>
23+ public static async Task < TResult > MatchAsync < TSuccess , TError , TResult > (
24+ this Task < Result < TSuccess , TError > > resultTask ,
25+ Func < TSuccess , Task < TResult > > onSuccess ,
26+ Func < TError , Task < TResult > > onFailure )
27+ {
28+ var result = await resultTask ;
29+ return await result . Match ( onSuccess , onFailure ) ;
30+ }
31+
32+ /// <summary>
33+ ///
34+ /// </summary>
35+ /// <typeparam name="TSuccess"></typeparam>
36+ /// <typeparam name="TError"></typeparam>
37+ /// <typeparam name="TResult"></typeparam>
38+ /// <param name="resultTask"></param>
39+ /// <param name="onSuccess"></param>
40+ /// <param name="onFailure"></param>
41+ /// <returns></returns>
42+ public static async Task < TResult > MatchAsync < TSuccess , TError , TResult > (
43+ this Task < Result < TSuccess , TError > > resultTask ,
44+ Func < TSuccess , TResult > onSuccess ,
45+ Func < TError , TResult > onFailure )
46+ {
47+ var result = await resultTask ;
48+ return result . Match ( onSuccess , onFailure ) ;
49+ }
50+
1351 /// <summary>
1452 /// Transforms the success value of a <see cref="Result{TSuccess, TError}" /> using the specified mapping function.
1553 /// </summary>
@@ -24,7 +62,7 @@ public static class ResultExtensions
2462 /// </returns>
2563 public static Result < TNew , TError > Map < TSuccess , TError , TNew > (
2664 this Result < TSuccess , TError > result ,
27- Func < TSuccess , TNew > map ) =>
65+ Func < TSuccess , TNew > map ) =>
2866 result . Match < Result < TNew , TError > > (
2967 ok => new Result < TNew , TError > . Ok ( map ( ok ) ) ,
3068 err => new Result < TNew , TError > . Error ( err )
0 commit comments