As it doesn't seem that a fully immutable object is possible in general (even
if it kinda works in this case, since there's nothing that needs to be hidden),
since all relevant data must pass through a public constructor.
Is a private constructor possible? If so, immutable objects can be doable.
interface GridInterface<A> {
get : (location: GridLocation) => A;
interface GridInterface<A> {
get : (location: GridLocation) => A;
- map : (f : (location: GridLocation) => A) => Grid<A>;
+ map : (f : (location: GridLocation) => A) => void;
moore_neighbors: (origin : GridLocation) => Array<GridLocation>;
print : (toString : (A: A) => string) => void;
};
moore_neighbors: (origin : GridLocation) => Array<GridLocation>;
print : (toString : (A: A) => string) => void;
};
cells[r][k] = f(location);
}
};
cells[r][k] = f(location);
}
};
- const init = ({r, k}) => cells[r][k];
- const grid = new Grid({rows: this.rows, columns: this.columns, init: init});
- return grid
};
private print_border(): void {
};
private print_border(): void {
- const grid = this.grid.map(
(location) => {
const neighbor_locations = this.grid.moore_neighbors(location);
const neighbor_states = neighbor_locations.map((l) => this.grid.get(l));
(location) => {
const neighbor_locations = this.grid.moore_neighbors(location);
const neighbor_states = neighbor_locations.map((l) => this.grid.get(l));