Trying to create an equivalent for decodeEvent using rescript-json-combinators. I couldn't figure out how to replace "Decoder(decoder)" since Decoders have been made abstract in rescript-json-combinators. Trying to use Decode.decode didn't work. Any idea on how this could be solved?
let decodeEvent = (Decoder(decoder), value: Web_node.event) =>
try decoder(Obj.magic(value)) catch {
| ParseFail(e) => Error(e)
| _ => Error("Unknown JSON parsing error")
}
The purpose of
decodeEventseems to be two-fold:Web_node.eventtoJson.tin order to use Json decoders on it.resultinstead of raising an exception on error.The
rescript-json-combinatorsAPI already has aresult-based API. That's part of the reason why the implementation is now hidden and requires the use ofJson.decodeto run the decoders. That seems to be all that's missing here: