(Function<Row,Row> fn)
| 1007 | } |
| 1008 | |
| 1009 | public Typing map(Function<Row,Row> fn) { |
| 1010 | Row[] nRows = matrix; |
| 1011 | // Sanity check existing rows |
| 1012 | for (int i = 0; i != nRows.length; ++i) { |
| 1013 | Row ith = nRows[i]; |
| 1014 | Row nith = fn.apply(ith); |
| 1015 | // Sanity check current type |
| 1016 | if(ith != nith && matrix == nRows) { |
| 1017 | nRows = Arrays.copyOf(nRows,nRows.length); |
| 1018 | } |
| 1019 | nRows[i] = nith; |
| 1020 | } |
| 1021 | if(matrix == nRows) { |
| 1022 | return Typing.this; |
| 1023 | } else { |
| 1024 | // Remove any invalid rows |
| 1025 | nRows = ArrayUtils.removeAll(nRows, null); |
| 1026 | // Recalculate number of variables |
| 1027 | int nVariables = nRows.length > 0 ? nRows[0].size() : 0; |
| 1028 | // Create new typing |
| 1029 | return new Typing(subtyping, frames, nVariables, nRows); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | public Typing fold(Comparator<Row> comparator) { |
| 1034 | if (matrix.length <= 1) { |
no test coverage detected