Last active
January 21, 2016 23:10
-
-
Save Porges/49186492c79f5d1289f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let bindArgumentsAndGenerateScript (args : Dictionary<string, _>) t = | |
let generateCall c = c |> bindArgument args <!> (sprintf "CALL %s") | |
let appendLine (stringBuilder : string) s = stringBuilder + s + "\n" | |
let generateTryCatchBlock (i, c) s = | |
let successLabel = sprintf "_success_%d" i | |
let errorLabel = sprintf "_error_%d" i | |
controlled { | |
let! sb = c.Try |> generateCall <!> appendLine s | |
// ... | |
let! sb = c.Catch |> Option.map generateCall |> getOrElse (Success "") <!> appendLine sb | |
// ... | |
return sprintf "" |> appendLine sb | |
} | |
controlled { | |
let! sb = t.TryCatchCommands |> List.mapi (fun i c -> (i, c)) |> List.fold (foldM generateTryCatchBlock) (Success "") | |
return! sprintf ":%s" finallyLabel |> Success <!> appendLine sb | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let bindArgumentsAndGenerateScript (args : Dictionary<string, _>) t = | |
let generateCall c = c |> bindArgument args <!> (sprintf "CALL %s") | |
let appendLine (stringBuilder : StringBuilder) s = stringBuilder.AppendLine(s) | |
let generateTryCatchBlock (i, c) sb = | |
let successLabel = sprintf "_success_%d" i | |
let errorLabel = sprintf "_error_%d" i | |
controlled { | |
let! sb = c.Try |> generateCall <!> appendLine sb | |
// ... | |
let! sb = c.Catch |> Option.map generateCall |> getOrElse (Success "") <!> appendLine sb | |
// ... | |
return sprintf "" |> appendLine sb | |
} | |
controlled { | |
let foldrM f z = List.fold (fun m a -> m >>= f a) (Success z) | |
let! sb = t.TryCatchCommands |> List.mapi (fun i c -> (i, c)) |> foldrM generateTryCatchBlock (StringBuilder()) | |
return! sprintf ":%s" finallyLabel |> Success <!> appendLine sb | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment