public static R Match <A, R>(this TryOption <A> self, Func <A, R> Some, Func <R> None, Func <Exception, R> Fail) { var res = TryOptionExtensions.Try(self); return(res.IsFaulted ? Fail(res.Exception) : res.Value.IsSome ? Some(res.Value.Value) : None()); }
public static S TriFold <A, S>(this TryOption <A> self, S state, Func <S, A, S> Some, Func <S, S> None, Func <S, Exception, S> Fail) { var res = TryOptionExtensions.Try(self); return(res.IsFaulted ? Fail(state, res.Exception) : res.Value.IsSome ? Some(state, res.Value.Value) : None(state)); }
/// <summary> /// Invoke a delegate if the Try is in a Fail or None state /// </summary> /// <param name="None">Delegate to invoke if successful</param> public static Unit IfNoneOrFail <A>(this TryOption <A> self, Action None) { var res = TryOptionExtensions.Try(self); if (res.IsFaulted || res.Value.IsNone) { None(); } return(unit); }
/// <summary> /// Invoke a delegate if the Try returns a value successfully /// </summary> /// <param name="Some">Delegate to invoke if successful</param> public static Unit IfSome <A>(this TryOption <A> self, Action <A> Some) { var res = TryOptionExtensions.Try(self); if (!res.IsFaulted && res.Value.IsSome) { Some(res.Value.Value); } return(unit); }
public static IObservable <R> MatchObservable <A, R>(this TryOption <A> self, Func <A, R> Some, Func <IObservable <R> > None, Func <Exception, IObservable <R> > Fail) { var res = TryOptionExtensions.Try(self); return(res.IsFaulted ? Fail(res.Exception) : res.Value.IsSome ? Observable.Return(Some(res.Value.Value)) : None()); }
public static A IfNoneOrFail <A>(this TryOption <A> self, Func <A> None) { var res = TryOptionExtensions.Try(self); if (res.IsFaulted || res.Value.IsNone) { return(None()); } else { return(res.Value.Value); } }
public static R Match <A, R>(this TryOption <A> self, Func <A, R> Some, R Fail) { if (isnull(Fail)) { throw new ArgumentNullException(nameof(Fail)); } var res = TryOptionExtensions.Try(self); return(res.IsFaulted || res.Value.IsNone ? Fail : Some(res.Value.Value)); }
public static ExceptionMatch <Option <A> > IfFail <A>(this TryOption <A> self) { var res = TryOptionExtensions.Try(self); if (res.IsFaulted) { return(res.Exception.Match <Option <A> >()); } else { return(new ExceptionMatch <Option <A> >(res.Value)); } }
public static ExceptionMatch <Option <A> > IfFail <A>(this TryOption <A> self) { var res = TryOptionExtensions.Try(self); // BUG/TODO what about IsBottom (res.Exception might be null!) if (res.IsFaulted) { return(res.Exception.Match <Option <A> >()); } else { return(new ExceptionMatch <Option <A> >(res.Value)); } }
/// <summary> /// Pattern matches the two possible states of the Try computation /// </summary> /// <param name="Some">Delegate to invoke if the Try computation completes successfully</param> /// <param name="Fail">Delegate to invoke if the Try computation fails</param> public static Unit Match <A>(this TryOption <A> self, Action <A> Some, Action Fail) { var res = TryOptionExtensions.Try(self); if (res.IsFaulted || res.Value.IsNone) { Fail(); } else { Some(res.Value.Value); } return(Unit.Default); }
public static A IfNoneOrFail <A>(this TryOption <A> self, A defaultValue) { if (isnull(defaultValue)) { throw new ArgumentNullException(nameof(defaultValue)); } var res = TryOptionExtensions.Try(self); if (res.IsFaulted || res.Value.IsNone) { return(defaultValue); } else { return(res.Value.Value); } }
public static A IfNoneOrFail <A>( this TryOption <A> self, Func <A> None, Func <Exception, A> Fail) { var res = TryOptionExtensions.Try(self); if (res.IsBottom) { return(Fail(res.Exception ?? new BottomException())); } else if (res.IsFaulted) { return(Fail(res.Exception)); } else if (res.Value.IsNone) { return(None()); } else { return(res.Value.Value); } }