Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about deserializeWith? #79

Open
haf opened this issue Nov 24, 2016 · 1 comment
Open

How about deserializeWith? #79

haf opened this issue Nov 24, 2016 · 1 comment

Comments

@haf
Copy link
Contributor

haf commented Nov 24, 2016

  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
Copy link

Dzoukr commented Jul 31, 2017

This would be really handy since there is already serializeWith.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants