Suppose I am looping over a partitioned set. I would like to check a condition or compare a value in the current partition to that of a partition used in a previous iteration or to be used in a future iteration. What would be the best way to do so?
In an unpartitioned set I could perform comparisons like
set = rand(collect(1:10),100) for k in eachindex(set) if k >1 println(max(set[k], set[k-1])) end end
But how would something similar be accomplished in a partitioned set of n elements? Say the goal is to compare the ith element of a partition to the corresponding element in the previous iteration. Where i = n it would be something like.
n = 5 g = Iterators.partition(set,n) for (k,x) in enumerate(g) if k >1 println( max( x[end] , set[(k-1)*n])) end end
Could I access the partition
x from the
k-1 iteration or more generally the k +/- j iteration directly without having to reference
Because this would make it easier for situations where i != n or for cycling through
set continuously where reverting to a simple
% would yield an error when set[100 ] is indexed as set e.g.
for (k,x) in enumerate(Iterators.cycle(g)) if k>1 println( max( x[end] , set[((k-1)*n)%100])) end end