1
- //Use project level define(s) when referencing with Paket.
2
- //#define CSX_EITHER_INTERNAL // Uncomment this to set visibility to internal.
3
- //#define CSX_REM_MAYBE_FUNC // Uncomment this to remove dependency to Maybe.cs.
1
+ //#define CSX_EITHER_INTERNAL // Uncomment or define at build time to set accessibility to internal.
2
+ //#define CSX_REM_MAYBE_FUNC // Uncomment or define at build time to remove dependency to Maybe.cs.
4
3
5
4
using System ;
6
5
@@ -133,8 +132,7 @@ public static Either<string, TRight> Fail<TRight>(string message)
133
132
public static Either < TLeft , TResult > Bind < TLeft , TRight , TResult > ( Either < TLeft , TRight > either , Func < TRight , Either < TLeft , TResult > > func )
134
133
{
135
134
TRight right ;
136
- if ( either . MatchRight ( out right ) )
137
- {
135
+ if ( either . MatchRight ( out right ) ) {
138
136
return func ( right ) ;
139
137
}
140
138
return Either . Left < TLeft , TResult > ( either . GetLeft ( ) ) ;
@@ -148,8 +146,7 @@ public static Either<TLeft, TResult> Bind<TLeft, TRight, TResult>(Either<TLeft,
148
146
public static Either < TLeft , TResult > Map < TLeft , TRight , TResult > ( Either < TLeft , TRight > either , Func < TRight , TResult > func )
149
147
{
150
148
TRight right ;
151
- if ( either . MatchRight ( out right ) )
152
- {
149
+ if ( either . MatchRight ( out right ) ) {
153
150
return Either . Right < TLeft , TResult > ( func ( right ) ) ;
154
151
}
155
152
return Either . Left < TLeft , TResult > ( either . GetLeft ( ) ) ;
@@ -164,8 +161,7 @@ public static Either<TLeft, TResult> Map<TLeft, TRight, TResult>(Either<TLeft, T
164
161
public static Either < TLeft1 , TRight1 > Bimap < TLeft , TRight , TLeft1 , TRight1 > ( Either < TLeft , TRight > either , Func < TLeft , TLeft1 > mapLeft , Func < TRight , TRight1 > mapRight )
165
162
{
166
163
TRight right ;
167
- if ( either . MatchRight ( out right ) )
168
- {
164
+ if ( either . MatchRight ( out right ) ) {
169
165
return Either . Right < TLeft1 , TRight1 > ( mapRight ( right ) ) ;
170
166
}
171
167
return Either . Left < TLeft1 , TRight1 > ( mapLeft ( either . GetLeft ( ) ) ) ;
@@ -196,9 +192,10 @@ public static Either<TLeft, TResult> SelectMany<TLeft, TRight, TResult>(this Eit
196
192
public static TRight GetOrFail < TLeft , TRight > ( Either < TLeft , TRight > either )
197
193
{
198
194
TRight value ;
199
- if ( either . MatchRight ( out value ) )
195
+ if ( either . MatchRight ( out value ) ) {
200
196
return value ;
201
- throw new ArgumentException ( "either" , string . Format ( "The either value was Left {0}" , either ) ) ;
197
+ }
198
+ throw new ArgumentException ( nameof ( either ) , string . Format ( "The either value was Left {0}" , either ) ) ;
202
199
}
203
200
204
201
/// <summary>
@@ -224,12 +221,10 @@ public static TRight GetRightOrDefault<TLeft, TRight>(Either<TLeft, TRight> eith
224
221
/// </summary>
225
222
public static Either < Exception , TRight > Try < TRight > ( Func < TRight > func )
226
223
{
227
- try
228
- {
224
+ try {
229
225
return new Right < Exception , TRight > ( func ( ) ) ;
230
226
}
231
- catch ( Exception ex )
232
- {
227
+ catch ( Exception ex ) {
233
228
return new Left < Exception , TRight > ( ex ) ;
234
229
}
235
230
}
@@ -244,10 +239,9 @@ public static Either<Exception, TRight> Cast<TRight>(object obj)
244
239
}
245
240
246
241
#if ! CSX_REM_MAYBE_FUNC
247
- public static Either < TLeft , TRight > OfMaybe < TLeft , TRight > ( Maybe < TRight > maybe , TLeft left )
242
+ public static Either < TLeft , TRight > FromMaybe < TLeft , TRight > ( Maybe < TRight > maybe , TLeft left )
248
243
{
249
- if ( maybe . Tag == MaybeType . Just )
250
- {
244
+ if ( maybe . Tag == MaybeType . Just ) {
251
245
return Either . Right < TLeft , TRight > ( ( ( Just < TRight > ) maybe ) . Value ) ;
252
246
}
253
247
return Either . Left < TLeft , TRight > ( left ) ;
@@ -269,8 +263,7 @@ static class EitherExtensions
269
263
public static void Match < TLeft , TRight > ( this Either < TLeft , TRight > either , Action < TLeft > ifLeft , Action < TRight > ifRight )
270
264
{
271
265
TLeft left ;
272
- if ( either . MatchLeft ( out left ) )
273
- {
266
+ if ( either . MatchLeft ( out left ) ) {
274
267
ifLeft ( left ) ;
275
268
return ;
276
269
}
@@ -279,7 +272,7 @@ public static void Match<TLeft, TRight>(this Either<TLeft, TRight> either, Actio
279
272
#endregion
280
273
281
274
/// <summary>
282
- /// Equivalent to monadic <see cref="CSharpx.Either.Return{TRight}"/> operation.
275
+ /// Equivalent to monadic <see cref="CSharpx.Either.Return{TLeft, TRight}"/> operation.
283
276
/// Builds a <see cref="CSharpx.Right{TLeft, TRight}"/> value in case <paramref name="value"/> by default.
284
277
/// </summary>
285
278
public static Either < string , TRight > ToEither < TRight > ( this TRight value )
0 commit comments