Skip to content

Instantly share code, notes, and snippets.

@mausch
Created April 7, 2014 15:12
Show Gist options
  • Save mausch/10022178 to your computer and use it in GitHub Desktop.
Save mausch/10022178 to your computer and use it in GitHub Desktop.
// Install http://www.nuget.org/packages/Fleece
open Fleece
open FSharpPlus
let json = """{
"1": "one",
"2": "two",
"3": "three"
}"""
let intMap =
monad {
let! stringMap = parseJSON json : Map<string, string> ParseResult
let! kvParsed = stringMap |> traverse (fun (KeyValue(k,v)) ->
match tryParse k : int option with
| Some i -> Success (i,v)
| _ -> Failure ("Invalid integer " + k))
return Map.ofSeq kvParsed
}
// intMap is of type Choice<Map<int, string>, string>
printfn "%A" intMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment