返回用户定义的类类型Scala的列表
我试图返回下面函数中未满的所有列的列表。“isColumnFull”函数将检查列表是否已满。游戏状态是一个列表列表。我不确定哪里出了错。你能帮忙吗返回用户定义的类类型Scala的列表,scala,list,indexing,functional-programming,Scala,List,Indexing,Functional Programming,我试图返回下面函数中未满的所有列的列表。“isColumnFull”函数将检查列表是否已满。游戏状态是一个列表列表。我不确定哪里出了错。你能帮忙吗 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
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)}
type GameState=List[List[String]]
案例类ColumnNum(索引:Int)
val count=0//不确定是否需要此值
def allViableColumns(游戏:游戏状态):列表[ColumnNum]=
对于((xs,count),如果需要列的索引:
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)
如果您决定使用第一个版本,请考虑将<代码>(I+1)< /COD> > <代码> i>代码>:对于基于一个索引,通常没有很好的理由。
def allViableColumns(game: GameState): List[List[String]] =
game filterNot isColumnFull