Created
April 7, 2014 15:12
-
-
Save mausch/10022178 to your computer and use it in GitHub Desktop.
This file contains 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
// 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