Created
February 7, 2017 22:12
-
-
Save a-dminator/da218f37161c369aae6fb51ea2aa26f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val validators = mapOf( | |
String::class to { s: String -> s != "123" }) | |
inline fun <vararg T, R> validate(vars: tuple<T>, action: (tuple<T>) -> R): R? = | |
if (vars.all { validators(it::class)(it) }) | |
action(vars) | |
else | |
null | |
get("/methor") { request, _ -> | |
validate( | |
request.queryParams("key1"), | |
request.queryParams("key2")) { (v1, v2) -> | |
// do something | |
} | |
} | |
inline fun <vararg T, R> guard(vars: tuple<T>, action: (tuple<T>) -> R): R? = | |
if (vars.all { it != null }) | |
action(vars) | |
else | |
null | |
val sum = guard(1, 2, null) { (a, b, c) -> | |
a+b+c | |
} ?: return null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment