以下两段代码如何等效?(案例如何运作)
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)
您可能对第二个示例中的错误名称感到困惑。我把它改成:
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)
| 归档时间: |
|
| 查看次数: |
1626 次 |
| 最近记录: |