您现在的位置是:主页 > news > 网站建设logo/个人网站怎么做
网站建设logo/个人网站怎么做
admin2025/4/26 3:07:55【news】
简介网站建设logo,个人网站怎么做,网站打开慢什么原因,报告怎么写理解偏函数的概念 传入部分参数 得到新函数 仔细体会与Currying的不同 面向场景不同 Currying一串函数调用 了解 偏函数的实现方法 package com.yzdzy.kotlin.chapter5.curryingimport com.sun.org.apache.xpath.internal.functions.Function2Args import java.io.OutputStr…
网站建设logo,个人网站怎么做,网站打开慢什么原因,报告怎么写理解偏函数的概念 传入部分参数 得到新函数
仔细体会与Currying的不同 面向场景不同 Currying一串函数调用
了解 偏函数的实现方法 package com.yzdzy.kotlin.chapter5.curryingimport com.sun.org.apache.xpath.internal.functions.Function2Args
import java.io.OutputStr…
理解偏函数的概念
-
传入部分参数 得到新函数
仔细体会与Currying的不同
-
面向场景不同 Currying一串函数调用
了解 偏函数的实现方法
package com.yzdzy.kotlin.chapter5.curryingimport com.sun.org.apache.xpath.internal.functions.Function2Args
import java.io.OutputStream
import java.nio.charset.Charsetfun log(tag: String, target: OutputStream, message: Any?) {target.write("[$tag] $message\n".toByteArray())}//fun log(tag: String) = fun(target: OutputStream) = fun(message: Any?) = target.write("[$tag] $message\n".toByteArray())fun <P1, P2, P3, R> Function3<P1, P2, P3, R>.curried() =fun(p1: P1) = fun(p2: P2) = fun(p3: P3) = this(p1, p2, p3)fun main(args: Array<String>) {log("benny", System.out, "Hello world")::log.curried()("benny")(System.out)("Hello world again")//原函数的偏函数val consoleLogWithTag = (::log.curried()("benny")(System.out))consoleLogWithTag("Hello Agagin1")consoleLogWithTag("Hello Agagin2")consoleLogWithTag("Hello Agagin3")val bytes="我是中国人".toByteArray(charset("GBK"))//偏函数val StringFromGBK= makeStringFromGbkBytes(bytes)}//上面的偏函数都是已经设置了签名的参数 后面再去使用 下面的案列将自定义第二个函数 然后传递前面的函数就行了
val makeString = fun(byteArray: ByteArray, charset: Charset): String {return String(byteArray)
}//
val makeStringFromGbkBytes = makeString.partial2(charset("GBK"))fun <P1, P2, R> Function2<P1, P2, R>.partial2(p2: P2) = fun(p1: P1) = this(p1, p2)
fun <P1, P2, R> Function2<P1, P2, R>.partial1(p1: P1) = fun(p2: P2) = this(p1, p2)