data_schema
data_schema copied to clipboard
Experiment with producing arbitrary data types from the schemas
Currently the library is focused around emitting a Struct from some arbitrary input data.
This is fine and good but the way we do that is with a reduce
, which makes me wonder if it's possible to have schemas reduce into any arbitrary data type. It would be fun to explore this.
A use case could be using data_schema to parse API responses, but then also wanting to serialise requests from a struct, for example. So the flow would be:
API response (xml) => Struct => biz logic happens
||
API request (xml) <============ Struct
An early idea is perhaps schemas have another attr like @accumulator %MyStruct{}
or @serialises_to ""
that we can provide as the accumulator.
We'd probably end up making another fn that to_struct
calls that does the reduce.
This could possible clean up the whole "reducing to a map" thing in the runtime schemas....