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

Make Validation contravariant #151

Merged
merged 8 commits into from
Oct 29, 2024
Merged

Make Validation contravariant #151

merged 8 commits into from
Oct 29, 2024

Conversation

dhoepelman
Copy link
Collaborator

@dhoepelman dhoepelman commented Oct 27, 2024

A Validation<Animal> should be usable as a Validation<Cat>, since animalValidation.validate(cat) is valid.

Allowed:

val animalValidation = Validation<Animal> {}
// Can use for subtype
val catValidation: Validation<Cat> = animalValidation
val catValidation2 = Validation<Cat> { run(animalValidation) }

Compile error since it makes no sense (not every animal is a cat)

val animalValidation: Validation<Animal> = catValidation
val animalValidation = Validation<Animal> { run(catValidation) }

@dhoepelman dhoepelman changed the title Add variance to Validation Make Validation contravariant Oct 29, 2024
@dhoepelman dhoepelman marked this pull request as ready for review October 29, 2024 15:08
@dhoepelman dhoepelman enabled auto-merge (squash) October 29, 2024 15:37
@dhoepelman dhoepelman disabled auto-merge October 29, 2024 19:35
@dhoepelman dhoepelman merged commit f5b0a7c into main Oct 29, 2024
2 checks passed
@dhoepelman dhoepelman deleted the validation-variance branch October 29, 2024 19:36
@dhoepelman dhoepelman added this to the v0.8.0 milestone Oct 31, 2024
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

Successfully merging this pull request may close these issues.

1 participant