public function map(callable $callback) : self
{
$literal = [];
for ($i = 0, $rows = $this->getRowCount(); $i < $rows; $i++) {
$row = [];
for ($j = 0, $columns = $this->getColumnCount(); $j < $columns; $j++) {
$row[] = $callback($this->get($i, $j), $i, $j, $this);
}
$literal[] = $row;
}
return new static($literal);
}
public function testMap() { $matrix = new Matrix([[1, 2], [3, 4]]); $mapped = $matrix->map(function ($value, $row, $column) { return $value + $row + $column; }); static::assertEquals(1, $mapped->get(0, 0)); static::assertEquals(3, $mapped->get(0, 1)); static::assertEquals(4, $mapped->get(1, 0)); static::assertEquals(6, $mapped->get(1, 1)); }