Allow parser customizations via protocol #203
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Had some slack time on a train ride and decided to give a patch for addressing #105 a shot.
This patch introduces the
IParser
protocol for customizing how values are parsed (except for booleans and null). It subsumes the already existing customization optionskey-fn
,array-coerce-fn
and*use-bigdecimals?*
(seebackwards-compatible-parser
). For maximal performance, users should reify a parser once and share it across parser invocations. The default parser is shared by default.Benchmarks show negligible overhead. To that end, care was taken that the existing inlineable parsers continue to be inlined when possible. Attached are the outputs of
lein benchmark
before and after the patch. For quick comparison, here's the mean execution times:A first test serving as an example based on the usecase from #105 is included. I stopped there as a PoC to save effort in case this patch is not accepted. Otherwise, I'm happy to add more tests, some clarifying code comments and a corresponding documentation section.