Skip to content

Instantly share code, notes, and snippets.

@Porges
Last active January 21, 2016 23:10
Show Gist options
  • Save Porges/49186492c79f5d1289f6 to your computer and use it in GitHub Desktop.
Save Porges/49186492c79f5d1289f6 to your computer and use it in GitHub Desktop.
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
}
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