kotlin入门-柯里化函数调用链

1.多元函数变换成一元函数调用链

fun log(tag: String) = fun(target: OutputStream) = fun(message: Any) = target.write("$tag-$message\n".toByteArray())

fun log1(tag:String,target:OutputStream,message: Any){
    target.write("$tag-$message \n".toByteArray())
}

fun main(args: Array) {
    log("日志")(System.out)("记录日志1")
    ::log1.curried()("日志")(System.out)("记录日志2")

}

fun  Function3.curried() = fun(p1: P1) = fun(p2: P2) = fun(p3: P3) = this(p1, p2, p3)


你可能感兴趣的:(kotlin)