I have a 2D list like so:
type Board = List[List[Option[Move]]]
looking a bit like this:
None None Some(X)
None None None
None None None
I can do things to row using the usual collection methods, map, fold etc. But I want to be able to operate on the columns in a similar fashion. I’ve been trying for about 1 hr with no luck (mindblank) for a method like so:
def getColumn(board: Board, column: Int): List[Option[Move]]
Given the above array, calling getColumn(board, 2), I should receive List(None, None, Some(X))
I believe you’re looking for is List.transpose. This will essentially rotate the list such that all of the columns will be grouped together. So your method could be: