public void WithoutExceptionEitherShouldBeRight() { var tryIo = Either.Catch(() => "noError"); Assert.True(tryIo.IsSuccess()); Assert.AreEqual("noError", tryIo.SuccessValue); }
public void WithExceptionEitherShouldBeLeft() { var tryIo = Either.Catch <Unit>(() => { throw new Exception("anError"); }); Assert.True(tryIo.IsFailure()); Assert.AreEqual("anError", tryIo.FailureValue.Message); }
private bool CheckPlatformAssistedTrackingSupport() { Debug.Log($"Count:{Count}"); lock (Tracker) { if (++Count >= 100) { return(false); } { Either.Catch(() => (Action)(() => Tracker.IsPlatformAssistedTrackingSupported(UpdateTrackingMessage))). SuccessOr(() => Async.Sleep(30).Then(() => Async.Return(CheckPlatformAssistedTrackingSupport)).RunSynchronously()); } return(true); } }
/// <summary> /// When computation completes successfully returns Either.Success with the returned value, otherwise Either.Failure with the exception. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="m"></param> /// <returns></returns> public static Async <Either <T, Exception> > Catch <T>(this Async <T> m) { return(() => Either.Catch <T>(m.RunSynchronously)); }
public static Maybe <T> Find <T>(this ImmutableList <T> xs, Func <T, bool> f) { return(Either.Catch <T>(xs.Choose <T, T>(x => f(x) ? Maybe.Just <T>(x) : Maybe.Nothing <T>()).First) .From <T, Exception, Maybe <T> >(Maybe.Just <T>, _ => Maybe.Nothing <T>())); }