Is there such a thing as a SQL-like “trigger” for arrays within a struct in Julia? I have an immutable struct, foo, that stores lots of pieces of information which get consumed by other functions. Two of the elements of foo are “entangled.” The first piece is “data” (a nxm array that’s input by the user) and the second piece is “fcalc”, a nx(m-1) array that’s calculated by the code. Imagine something like this:
struct foo ... data fcalc ... end
fcalc is simply the columns of data divided by the preceding columns of data, and to construct foo I do something like:
function create_foo(..., data,...) ... for j = 1:(size(data, 2) - 1) for i = 1:size(data, 1) fcalc[i, j] = data[i, j + 1] / data[i, j] end end ... return foo(..., data, fcalc,...) end
foo is immutable but the elements of data are mutable, which is desirable, however, if data gets modified then fcalc needs to be updated. How can I ensure that happens? Is there a way to trigger the update of fcalc when an element of data is modified? Is it possible for fcalc to be a “calculated view?” Everything I’ve tried with view, @view, and @views has failed. Any suggestions or options I should explore?