Lorin
05/27/2019, 7:32 AMfun main(args: Array<String>) {
fun <P1, P2, R> ((P1, P2) -> R).partial(p1: P1): (P2) -> R = { p2: P2 -> this(p1, p2) }
fun regexMatch(re: Regex, s: String): Boolean = re.containsMatchIn(s)
val match = ::regexMatch.partial(Regex("^123"))
println(match("12345"))
println(match("123xx"))
println(match("2345"))
println(match)
println(match.reflect()!!.run {
"(${parameters.map { it.type }.joinToString()}) -> $returnType" })
}
The output (the signature of match
) is (P2) -> R
.
Is there any way to infer the actual correct signature which should be (String) -> Boolean
?diesieben07
05/27/2019, 7:50 AMpartial
inline
you could mark all the type parameters as reified
, in which case you can (maybe) get the correct signature.Lorin
05/27/2019, 8:48 AMinline/reified
doesn't help.diesieben07
05/27/2019, 9:01 AMLorin
05/27/2019, 11:48 AM