Happy to have a run here
That’s pretty much why I asked for Skipping parts of a for loop in the first iteration
With that
"""
Return the run lengths of `==` elements in the iterable itr.
"""
function runlengths(itr)
lengths = Int[]
local runcount = 1
@unroll1 for elt in itr
if $first
lastelt = elt
else
if elt == lastelt
runcount += 1
else
push!(lengths, runcount)
lastelt = elt
runcount = 1
end
end
end
push!(lengths, runcount)
lengths
end
The macro there is not well tested yet though, just had to esc
some more expression to make the example run, see
https://gist.github.com/mschauer/9265bd5b70c9abf1391d4ef541d53eca