Skip to content

Instantly share code, notes, and snippets.

@Dzoukr
Last active August 14, 2017 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dzoukr/a48e5b2d58f91b3a7638997ea40a44fb to your computer and use it in GitHub Desktop.
Save Dzoukr/a48e5b2d58f91b3a7638997ea40a44fb to your computer and use it in GitHub Desktop.
module Chiron.Extensions
let tryDeserializeWith (fromJson : Json<'a>) : Json -> Choice<'a, string> =
fun json ->
match fromJson json with
| JsonResult.Value x, _ -> Choice1Of2(x)
| JsonResult.Error err, _ -> Choice2Of2(err)
let tryDeserializeWithP (_, fromJson : Json<'a>) : Json -> Choice<'a, string> =
tryDeserializeWith fromJson
let deserializeWith (fromJson : Json<'a>) : Json -> 'a =
fun json ->
match tryDeserializeWith fromJson json with
| Choice1Of2 x -> x
| Choice2Of2 err -> failwith err
let deserializeWithP (_, fromJson : Json<'a>) : Json -> 'a =
deserializeWith fromJson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment