Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think all of those problems are only true when you try to do coercion with custom conformers. Which is not the intended use of conformers.

Conformers are meant to parse the data when there are multiple possibility of what something can validate against, the conformer will disambiguate and return a result that tells you which path was chosen.

Coercion is not supported as part of Spec, you're expected to do that seperatly either before or after validating/conforming.



Yes, that was largely my point. Many people (me included) assume that s/conform is a kind of coercion, which it is not.

Not all of the above problems are due to coercion, but the majority are.

To be clear: I'm not complaining here, I find spec to be very useful and I like it, just pointing out traps for the unwary.


Ya fair enough, I've definitely seen a lot of people think conforming is meant for coercion. But it's not, it's only meant for disambiguating the chosen path (when multiple are possible) for validation.


There are a few libraries that make it possible without abusing conformers, one of which is https://github.com/exoscale/coax


Looks nice, I knew of spec-coerce, but not coax.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: