Kotlin 中的高阶函数:
我有一个使用 wto 高阶函数的类:
data class Data(id: String)
class MyClass(
private val getData: (find1: (String) -> Data?, find2: (String) -> Data?) -> (Request) -> Either<HttpError, Data>
)
我在对象内部定义了 getData 函数。
object Data
{
fun getData(find1: (String) -> Data?, find2: (String) -> Data?): (Request) -> Either<HttpError, Data> = {...}
}
现在,我无法理解如何初始化类?
val obj = MyClass(
getData = {Data.getData ??? }
)
如何从 MyClass 类中调用此函数:
报告.kt
override fun find1(value: String): Data? {
}
repo1.kt
override fun find1(value: String): Data? {
}
class MyClass(repo: Repo, repo1: Repo1, private val getData: (find1: (String) -> Data?, find2: (String) -> Data?) -> (Request) -> Either<HttpError, Data>)
{
getData { id -> repo.find1(id) ?????}(request)
}