带和不带大小写的 zipWithIndex

use*_*615 2 collections scala

以下两段代码如何等效?(案例如何运作)

 list.zipWithIndex.flatMap{ 
     rowAndIndex =>
     rowAndIndex._1.zipWithIndex
}
Run Code Online (Sandbox Code Playgroud)

list.zipWithIndex.flatMap {
    case (rowAndIndex, r) =>
     rowAndIndex.zipWithIndex
}
Run Code Online (Sandbox Code Playgroud)

Ser*_*nko 5

您可能对第二个示例中的错误名称感到困惑。我把它改成:

list.zipWithIndex.flatMap {
    case (row, index) =>
     row.zipWithIndex
}
Run Code Online (Sandbox Code Playgroud)

这是以下的简短版本:

list.zipWithIndex.flatMap { rowAndIndex => 
  rowAndIndex match {
    case (row, index) => row.zipWithIndex
  }
}
Run Code Online (Sandbox Code Playgroud)