xyncro / chiron

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

Backwards-compatible reads #36

Closed haf closed 9 years ago

haf commented 9 years ago

A default function for 'this property might not exist, because it was introduced later:

  (fun ... -> ())
   <!> // ...
   <*> (Json.bind (Json.tryRead "images")
                  (function | None -> Json.init []
                            | Some x -> Json.init x))

By default I think it's a good idea to be backwards-compatible with schema, so if the library's user knows that a property has been introduced later, then there should be an easy way (i.e. one that doesn't require reasoning about the monad's structure) to read that properly optionally, like above.

kolektiv commented 9 years ago

Yeah, that seems useful - something like a function Json.readOrDefault if that's possible? It would make sense to have that I agree. How does 'readOrDefault' sound to you, and would that be the right thing?

haf commented 9 years ago

Yes, that sounds about right!

kolektiv commented 9 years ago

I'll have a look at it later on then and try and push it as a 4.1 :)

haf commented 9 years ago

Nice