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

Adding Fallback Schema #645

Merged
merged 1 commit into from
Jan 20, 2024
Merged

Adding Fallback Schema #645

merged 1 commit into from
Jan 20, 2024

Conversation

pablf
Copy link
Member

@pablf pablf commented Jan 20, 2024

/claim #584

Added a new Schema.Fallback[A, B] for a new sealed trait Fallback[A, B] with subclasses Left, Right and Both. The idea is to allow not only to decode from fallback semantics but to encode to them using just one schema.

The property fullDecode: Boolean in Schema.Fallback allows to completely retrieve a Fallback or to retrieve only the Left part from a Fallback.Both. So:

// with fullDecode = true
"""[3, "hello"]""" // decodes Fallback.Both(3, "hello")

// with fullDecode = false
"""[3, "hello"]""" // decodes Fallback.Left(3)

If it's not possible to decode the left member, it reads the right one:

// with a Schema.Fallback[Int, String]
"""["wrong", "right"]""" // decodes Fallback.Right("right")

(P.D. It seems like #588 is not possible to claim anymore)

@jdegoes jdegoes merged commit 6a0e914 into zio:main Jan 20, 2024
25 checks passed
@pablf
Copy link
Member Author

pablf commented Jan 21, 2024

Thanks :)

@pablf pablf deleted the schema-fallback branch January 23, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants