我正在尝试返回以下函数中未满的所有列的列表。"isColumnFull“函数将检查列表是否已满。GameState是list的列表。我不确定哪里出了错。你能帮帮忙吗?
type GameState = List[List[String]]
case class ColumnNum(index: Int)
val count = 0 //not sure this is needed
def allViableColumns(game: GameState): List[ColumnNum] =
for((xs, count) <- game.zipWithIndex) yield {if(!isColumnFull(xs))List(count+1)}
发布于 2018-06-02 07:42:31
如果您想要列的索引:
type GameState = List[List[String]]
case class ColumnNum(index: Int)
def allViableColumns(game: GameState): List[ColumnNum] =
for((xs, i) <- game.zipWithIndex; if !isColumnFull(xs)) yield ColumnNum(i + 1)
如果您想要列,只需:
def allViableColumns(game: GameState): List[List[String]] =
game filterNot isColumnFull
如果您决定使用第一个版本,请考虑将(i + 1)
更改为i
:基于一的索引通常没有很好的理由。
https://stackoverflow.com/questions/50652163
复制相似问题