11using System ;
2- using System . Diagnostics ;
32using System . Threading . Tasks ;
43
54namespace CSharpFunctionalExtensions
65{
76 public partial struct Result
87 {
98 public static Result CreateFailure ( bool isFailure , string error )
10- {
11- return isFailure
12- ? Fail ( error )
13- : Ok ( ) ;
14- }
9+ => Create ( ! isFailure , error ) ;
1510
1611 public static Result CreateFailure ( Func < bool > failurePredicate , string error )
17- {
18- return failurePredicate ( )
19- ? Fail ( error )
20- : Ok ( ) ;
21- }
12+ => Create ( ! failurePredicate ( ) , error ) ;
2213
2314 public static async Task < Result > CreateFailure ( Func < Task < bool > > failurePredicate , string error )
2415 {
25- bool isFailure = await failurePredicate ( ) . ConfigureAwait ( Result . DefaultConfigureAwait ) ;
26- return isFailure
27- ? Fail ( error )
28- : Ok ( ) ;
16+ bool isFailure = await failurePredicate ( ) . ConfigureAwait ( DefaultConfigureAwait ) ;
17+ return Create ( ! isFailure , error ) ;
2918 }
3019
3120 public static Result < T > CreateFailure < T > ( bool isFailure , T value , string error )
32- {
33- return isFailure
34- ? Fail < T > ( error )
35- : Ok < T > ( value ) ;
36- }
21+ => Create ( ! isFailure , value , error ) ;
3722
3823 public static Result < T > CreateFailure < T > ( Func < bool > failurePredicate , T value , string error )
39- {
40- return failurePredicate ( )
41- ? Fail < T > ( error )
42- : Ok < T > ( value ) ;
43- }
24+ => Create ( ! failurePredicate ( ) , value , error ) ;
4425
4526 public static async Task < Result < T > > CreateFailure < T > ( Func < Task < bool > > failurePredicate , T value , string error )
4627 {
47- bool isFailure = await failurePredicate ( ) . ConfigureAwait ( Result . DefaultConfigureAwait ) ;
48- return isFailure
49- ? Fail < T > ( error )
50- : Ok < T > ( value ) ;
28+ bool isFailure = await failurePredicate ( ) . ConfigureAwait ( DefaultConfigureAwait ) ;
29+ return Create ( ! isFailure , value , error ) ;
5130 }
5231
53- [ DebuggerStepThrough ]
5432 public static Result < T , E > CreateFailure < T , E > ( bool isFailure , T value , E error )
55- {
56- return isFailure
57- ? Fail < T , E > ( error )
58- : Ok < T , E > ( value ) ;
59- }
33+ => Create ( ! isFailure , value , error ) ;
6034
6135 public static Result < T , E > CreateFailure < T , E > ( Func < bool > failurePredicate , T value , E error )
62- {
63- return failurePredicate ( )
64- ? Fail < T , E > ( error )
65- : Ok < T , E > ( value ) ;
66- }
36+ => Create ( ! failurePredicate ( ) , value , error ) ;
6737
6838 public static async Task < Result < T , E > > CreateFailure < T , E > ( Func < Task < bool > > failurePredicate , T value , E error )
6939 {
70- bool isFailure = await failurePredicate ( ) . ConfigureAwait ( Result . DefaultConfigureAwait ) ;
71- return isFailure
72- ? Fail < T , E > ( error )
73- : Ok < T , E > ( value ) ;
40+ bool isFailure = await failurePredicate ( ) . ConfigureAwait ( DefaultConfigureAwait ) ;
41+ return Create ( ! isFailure , value , error ) ;
7442 }
7543 }
76- }
44+ }
0 commit comments