Skip to content

Commit 07562d0

Browse files
authored
Add row col based get to Grid2D.kt
1 parent 7378ce6 commit 07562d0

File tree

1 file changed

+3
-1
lines changed
  • src/main/kotlin/com/soberg/aoc/utlities/datastructures

1 file changed

+3
-1
lines changed

src/main/kotlin/com/soberg/aoc/utlities/datastructures/Grid2D.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ data class Grid2D<T>(
2121

2222
infix operator fun get(location: Location): T = grid[location.row][location.col]
2323

24+
fun get(row: Int, col: Int): T = grid[row][col]
25+
2426
/** @return true if the specified [location] is in the bounds of this grid, false if not. */
2527
fun isInBounds(location: Location): Boolean = isInBounds(location.row, location.col)
2628

@@ -92,4 +94,4 @@ data class Grid2D<T>(
9294
}
9395
}
9496

95-
fun <T> List<List<T>>.toGrid2D() = Grid2D(this)
97+
fun <T> List<List<T>>.toGrid2D() = Grid2D(this)

0 commit comments

Comments
 (0)