mlms13 / bs-decode

Type-safe JSON decoding for ReasonML and OCaml
https://mlms13.github.io/bs-decode/docs/what-and-why
MIT License
103 stars 18 forks source link

Add a null decoder #124

Closed mlms13 closed 1 year ago

mlms13 commented 1 year ago

null is a valid JSON value, so it makes sense to have a decoder that succeeds only if it encounters the literal null value.

On its own, it probably isn't the most useful decoder, but it should allow us to rewrite the optional decoder as

let optional =
  decoder => alt(null |> map(() => None), decoder |> map(Option.pure))
mlms13 commented 1 year ago

Not going to change the implementation of optional for 1.x because that would actually change the error that comes out of optional decoders. This will change in 2.0, though.