在Kotlin中,如何创建lambda列表,其中每个lambda的类型为(Int)->;列表I';我得到了解构声明错误

在Kotlin中,如何创建lambda列表,其中每个lambda的类型为(Int)->;列表I';我得到了解构声明错误,kotlin,Kotlin,我试图在Kotlin中创建lambda列表,但出现以下编译时错误: Destructuring declaration initializer of type Int must have a 'component1()' function 这是我的密码: val pathXRanges=listOf List>( {(extX)->((extX-(board.k-1))…(extX+board.k-1)).toList()},//对角线1(y=-x) {(extX)->((extX-(boa

我试图在Kotlin中创建lambda列表,但出现以下编译时错误:

 Destructuring declaration initializer of type Int must have a 'component1()' function
这是我的密码:

val pathXRanges=listOf List>(
{(extX)->((extX-(board.k-1))…(extX+board.k-1)).toList()},//对角线1(y=-x)
{(extX)->((extX-(board.k-1))…(extX+board.k-1)).toList()},//对角线2(y=x)
{(extX)->List(board.k*2-2){extX},//x=x
{(extX)->((extX-(board.k-1))…(extX+board.k-1)).toList()}//y=y
)
差不多就是这样!非常感谢您的帮助,如果您需要任何澄清,请告诉我


谢谢

只需从
extX
lambda参数值中删除括号即可,即:

    val pathXRanges = listOf<(Int) -> List<Int>>(
      { extX -> ((extX - (board.k - 1))..(extX + board.k - 1)).toList() }, // diagonal 1 (y = -x)
      { extX -> ((extX - (board.k - 1))..(extX + board.k - 1)).toList() }, // diagonal 2 (y = x)
      { extX -> List(board.k * 2 - 2) { extX } }, // x = x
      { extX -> ((extX - (board.k - 1))..(extX + board.k - 1)).toList() } // y = y
    )
Destructuring declaration initializer of type Int must have a 'component1()' function`.