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.
43
54using System ;
65
@@ -133,8 +132,7 @@ public static Either<string, TRight> Fail<TRight>(string message)
133132 public static Either < TLeft , TResult > Bind < TLeft , TRight , TResult > ( Either < TLeft , TRight > either , Func < TRight , Either < TLeft , TResult > > func )
134133 {
135134 TRight right ;
136- if ( either . MatchRight ( out right ) )
137- {
135+ if ( either . MatchRight ( out right ) ) {
138136 return func ( right ) ;
139137 }
140138 return Either . Left < TLeft , TResult > ( either . GetLeft ( ) ) ;
@@ -148,8 +146,7 @@ public static Either<TLeft, TResult> Bind<TLeft, TRight, TResult>(Either<TLeft,
148146 public static Either < TLeft , TResult > Map < TLeft , TRight , TResult > ( Either < TLeft , TRight > either , Func < TRight , TResult > func )
149147 {
150148 TRight right ;
151- if ( either . MatchRight ( out right ) )
152- {
149+ if ( either . MatchRight ( out right ) ) {
153150 return Either . Right < TLeft , TResult > ( func ( right ) ) ;
154151 }
155152 return Either . Left < TLeft , TResult > ( either . GetLeft ( ) ) ;
@@ -164,8 +161,7 @@ public static Either<TLeft, TResult> Map<TLeft, TRight, TResult>(Either<TLeft, T
164161 public static Either < TLeft1 , TRight1 > Bimap < TLeft , TRight , TLeft1 , TRight1 > ( Either < TLeft , TRight > either , Func < TLeft , TLeft1 > mapLeft , Func < TRight , TRight1 > mapRight )
165162 {
166163 TRight right ;
167- if ( either . MatchRight ( out right ) )
168- {
164+ if ( either . MatchRight ( out right ) ) {
169165 return Either . Right < TLeft1 , TRight1 > ( mapRight ( right ) ) ;
170166 }
171167 return Either . Left < TLeft1 , TRight1 > ( mapLeft ( either . GetLeft ( ) ) ) ;
@@ -196,9 +192,10 @@ public static Either<TLeft, TResult> SelectMany<TLeft, TRight, TResult>(this Eit
196192 public static TRight GetOrFail < TLeft , TRight > ( Either < TLeft , TRight > either )
197193 {
198194 TRight value ;
199- if ( either . MatchRight ( out value ) )
195+ if ( either . MatchRight ( out value ) ) {
200196 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 ) ) ;
202199 }
203200
204201 /// <summary>
@@ -224,12 +221,10 @@ public static TRight GetRightOrDefault<TLeft, TRight>(Either<TLeft, TRight> eith
224221 /// </summary>
225222 public static Either < Exception , TRight > Try < TRight > ( Func < TRight > func )
226223 {
227- try
228- {
224+ try {
229225 return new Right < Exception , TRight > ( func ( ) ) ;
230226 }
231- catch ( Exception ex )
232- {
227+ catch ( Exception ex ) {
233228 return new Left < Exception , TRight > ( ex ) ;
234229 }
235230 }
@@ -244,10 +239,9 @@ public static Either<Exception, TRight> Cast<TRight>(object obj)
244239 }
245240
246241#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 )
248243 {
249- if ( maybe . Tag == MaybeType . Just )
250- {
244+ if ( maybe . Tag == MaybeType . Just ) {
251245 return Either . Right < TLeft , TRight > ( ( ( Just < TRight > ) maybe ) . Value ) ;
252246 }
253247 return Either . Left < TLeft , TRight > ( left ) ;
@@ -269,8 +263,7 @@ static class EitherExtensions
269263 public static void Match < TLeft , TRight > ( this Either < TLeft , TRight > either , Action < TLeft > ifLeft , Action < TRight > ifRight )
270264 {
271265 TLeft left ;
272- if ( either . MatchLeft ( out left ) )
273- {
266+ if ( either . MatchLeft ( out left ) ) {
274267 ifLeft ( left ) ;
275268 return ;
276269 }
@@ -279,7 +272,7 @@ public static void Match<TLeft, TRight>(this Either<TLeft, TRight> either, Actio
279272 #endregion
280273
281274 /// <summary>
282- /// Equivalent to monadic <see cref="CSharpx.Either.Return{TRight}"/> operation.
275+ /// Equivalent to monadic <see cref="CSharpx.Either.Return{TLeft, TRight}"/> operation.
283276 /// Builds a <see cref="CSharpx.Right{TLeft, TRight}"/> value in case <paramref name="value"/> by default.
284277 /// </summary>
285278 public static Either < string , TRight > ToEither < TRight > ( this TRight value )
0 commit comments