Esempio n. 1
0
 ///<summary>
 ///Returns an action which attempts <paramref name="action"/> first, calls
 ///<paramref name="rescue"/> in case of failure.
 ///</summary>
 ///<param name="action">The action to try.</param>
 ///<param name="rescue">The action to call if <paramref name="action"/> fails.</param>
 public static ActionCPS <T> WithRescue <T>(this ActionCPS <T> action,
                                            Func <Exception, ActionCPS <T> > rescue)
 {
     return(cont => action.RunR().Match(
                t => cont.Ok(t),
                e => rescue(e)(cont)));
 }
Esempio n. 2
0
 ///<summary>
 ///Runs the action with the trivial continuation. Throws an
 ///<see cref="ActionFailureException"/> in the case action fails.
 ///</summary>
 ///<param name="action"></param>
 ///<typeparam name="T"></typeparam>
 public static T Run <T>(this ActionCPS <T> action)
 {
     return(action.RunR().Match(
                x => x,
                e => { throw new ActionFailureException(e); }));
 }