-
Notifications
You must be signed in to change notification settings - Fork 32
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
Data coercions #88
Comments
We could think about adding this feature. Thanks for the input! |
Great! I absolutely like your functional approach. Validations is a great use case for FP. It is also clear that one could build a layer on top to build objects returning an Either monad where the Left value is a result from spected. However the cut and focus on validations is great. People get the best of FP without having to understand FP. I can build more abstractions on top, but I am not so sure about coercions. I have the feeling that the most elegant solution is a combination of validation and coercions, but I can't figure out a clean/simple way to do it. |
Thank you very much for the feedback! Highly appreciated. |
If it helps, this is my line of thought: const normalizeString = (rules, {default}) => (value, f) => {
let before = value || 'anonymous'
let result = f(before)
// ignoring failed case
let after = _.toLowerCase(value)
return ... // after? custom struct? monad?
}
const validationRules = {
name: normalizeString([
[ isGreaterThan(5),
`Minimum Name length of 6 is required.`
],
]),
} After doing the coercion with
|
Good points. Will also think about how we can makes this efficient. |
I must retract myself in one of the points. Now I believe coercions must be done before validation. Any modification after validation seems to me now awfully conflicting (like setting invalid values) |
Is there any plan for adding field coercion along the validations?
The text was updated successfully, but these errors were encountered: