-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add function and lambda accessor syntax #65
Add function and lambda accessor syntax #65
Conversation
Looks interesting, I have definitely encountered this. On my list to review for inclusion |
If we wait long enough this will likely be solved by Kotlin itself, synthetic java accessors are scheduled for kotlin 2.1: Still, allowing constraints to be specified for any function/lambda seems a good feature to have in general, if only because I find it annoying to not be able to easily specify constraints on nested things. Supporting |
getPassword("getPasswordLambda") { | ||
minLength(1) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about this as an API for lambdas
getPassword("getPasswordLambda") { | |
minLength(1) | |
} | |
get("password", { it.password }) { | |
minLength(1) | |
} |
I think that should be possible with
/**
* Transform the value into anything else and add a validation for it.
* @param name The name that should be reported in validation errors
* @param prop The function to get the value you want add a validation on
* @see run
*/
abstract fun <R> get(name: String, prop: (T) -> R, init: ValidationBuilder<R>.() -> Unit)
Fixes #14 |
yep, I think this works for us |
This issue you may find interesting 🙂 |
@NikkyAI @jillesvangurp Thanks a lot for the contribution! I've massaged the API into something I think can provide a good basis, see the new README. Intend to release this soon-ish as 0.7.0. Let me know if you have any feedback. |
Great! |
may be a partial duplicate of #63 but have this code anyhow.. maybe it helps even a little bit
this allows validations of java libraries without needing to write a
val ThatClass.someValue = getSomeValue()
extensions for each propertyit also allows to use
aliased
custom accessorsa example out of our codebase using this to validate
com.nimbusds.jwt.SignedJWT
i added tests
functionAccessorSyntax
,lambdaAccessorSyntax
,complexLambdaAccessors
to demonstrate usage of this syntax