xyncro / chiron

JSON for F#
https://xyncro.tech/chiron
MIT License
173 stars 41 forks source link

How about deserializeWith? #79

Open haf opened 7 years ago

haf commented 7 years ago

  let tryDeserializeWith (fromJson : Json<'a>) : Json -> Choice<'a, string> =
    fun json ->
      match fromJson json with
      | JsonResult.Value x, _ -> Choice.create x
      | JsonResult.Error err, _ -> Choice.createSnd 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
Dzoukr commented 7 years ago

This would be really handy since there is already serializeWith.