I often want to pre-allocate a container for a bunch of views, but have no idea how to predict the type that view will return, and therefore don’t know how to make a container for them. I understand that this may be difficult to do in an extremely general way, but often my views end up being the same type anyways (e.g. a bunch of slices from the same array).
I typically just do typeof on an example. This is not a good generalizeable solution but is very cheap to implement even if you don’t understand anything about the view method or SubArray type (which I don’t).
Clever solution! I may start using something similar to that. I think the “pain” (which is really not that bad) to either your allocate or doing what @Juser suggested is that you have to break up for loops. You have to run the first element, pre-allocate, put the first element into the array, then run the rest. It’s fine for one offs but I find myself turning to map quite often to avoid having to do all of that.