Skip to content

travisbrown/circe-algebra

Repository files navigation

circe-algebra

Build status Coverage status Gitter Maven Central

This project contains a set of experiments related to some proposed changes to circe's JSON decoding mechanism.

The key idea is that instead of working directly with cursors for decoding (an approach that circe inherited from Argonaut but that I've never really been 100% on board with), we write decoders using a small algebra of navigation and reading operations. This algebra can then be interpreted in various contexts, where "context" includes both the underlying document representation and the result type.

This proposal has four major advantages over the cursor-based approach:

  1. It's a better fit for the problem. Cursors are too powerful—in order to be generally useful they support operations that aren't needed for decoding.
  2. It makes it possible to use the same decoders for multiple underlying representations. These could include JSON ASTs from other libraries, or even something like a BSON representation.
  3. It makes it easier to get fine-tuned result types from the same decoder. You don't need history in your error messages? Choose an interpreter that doesn't track history. You want error accumulation? Choose an error-accumulating interpreter. You just want stuff to be fast and don't mind exceptions getting thrown all over the place? Write an interpreter that returns everything in cats.Id.
  4. It makes it easier to optimize decoders, since they're just a data structure that you can inspect and rearrange however you want.

The code here is currently a work in progress—everything is subject to change and none of this may ever make it back into circe-core.

License

circe-algebra is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Experimental decoding algebra for circe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages