Suppose I have an array like
x = [ 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 ]
I want to loop over the sets of sequences of common numbers, using a syntax like:
for set in eachset(x)
...
end
Where eachset(x)
should behave as an array of sets.
If I define
eachset(x) = [ findall(isequal(i),x) for i in unique(x) ]
I get the indexes of the elements of each set and I could use that (although I only need the ranges really).
But I understand that I do not need to really allocate that array to iterate over its elements. What do I have to implement to get an iterator instead of an array?