I have a vector nested inside another. I want to use modify
to update this matrix in place. So I use it for the inner vector, but do I also need to use it for the outer?
Data.Vector.modify with nested vectors
448 views Asked by Lo HaBuyshan At
1
My suggestion from the comments still stands, if you do not need to operate on a ragged array then the usual rectangular array implementation is better. Here is a short list of drawbacks of vector of vectors:
Nevertheless question still stands: how would you modify a vector of vectors in place. Below I'll provide an example function, which uses mutation to reverse rows of a ragged array and another function that reverses both rows and columns. Difference is that in the former we only mutate elements of each row, while in the latter we also mutate the outer boxed vector that corresponds to rows themselves:
Which can be used as follows:
Alternatively we could have used
Data.Vector.modify
to operate on the outer vector or map a destructive action that usesmodify
across all rows. There are all sorts of ways to go about it, depends on what you are trying to achieve, for example:I did recommend using
massiv
for regular multidimensional arrays. Therefore here is also an example of how to achieve the same withwithMArrayST
:Which can be used as follows: