struct Matrix { var width: Int var height: Int var data: [Element] init(width: Int, height: Int, data: [Element]) { precondition(data.count == width * height) self.width = width self.height = height self.data = data } subscript(x: Int, y: Int) -> Element { get { precondition(0 <= x && x < width && 0 <= y && y < height) return data[x + width * y] } set { precondition(0 <= x && x < width && 0 <= y && y < height) data[x + width * y] = newValue } } } extension Matrix { func map(_ transform: (Element) throws -> T) rethrows -> Matrix { Matrix(width: width, height: height, data: try data.map(transform)) } func mapIndexed(_ transform: (Int, Int, Element) throws -> T) rethrows -> Matrix { var newData: [T] = [] newData.reserveCapacity(data.count) var index = 0 for y in 0..(width: width, height: height, data: newData) } func find(where: (Element) throws -> Bool) rethrows -> [(Int, Int)] { var result: [(Int, Int)] = [] var index = 0 for y in 0..