Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iso schemas aren't enough #33

Open
vil1 opened this issue Jan 4, 2019 · 1 comment
Open

Iso schemas aren't enough #33

vil1 opened this issue Jan 4, 2019 · 1 comment

Comments

@vil1
Copy link
Member

vil1 commented Jan 4, 2019

With only IsoSchema, we cannot define schemas such as "dates represented as JSON strings":

val dateSchema = iso(prim(JsonString), stringToDate)

Because we cannot implement a correct Iso that goes from String to Date. We could go from String to Option[Date] with an isomorphism, but that of course doesn't cover all the use cases.

A simple solution would be to add a PrismSchema to the schema GADT, same as IsoSchema but with a Prism instead of an Iso. Interpreter for covariant functors would then use this new node to handle errors and contravariant ones would use it the same way they use IsoSchema.

If we go down that road, the public API should be adapted carefully. I'd rather not add a prism combinator, because it would be easily confused with prim. Ideally, I'd like to have a unique combinator for "a schema seen through an optic" that would build an IsoSchema or a PrismSchema depending on the argument it is passed, be it an Iso or a Prism.

@vil1 vil1 closed this as completed Feb 10, 2020
@vil1 vil1 reopened this Feb 10, 2020
@julienrf
Copy link
Collaborator

Note that by returning Option[Date] you can not provide helpful error messages in decoder interpreters. You will have to return something like Validated[Date].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants