Grasping `all-the-apples-at-once' › 解法样本 Sample solutions › Julia (Group II) [#286]

function rle(itr)
   acc = Tuple{eltype(itr), Int}[]
   x = iterate(itr)
   isnothing(x) && return acc # iterable is empty
   last, state = x
   n = 1
   for v in Iterators.rest(itr, state)
           if last == v
                   n += 1
           else
                   push!(acc, (last, n))
                   last = v
                   n = 1
           end
   end
   push!(acc, (last, n))
   return acc
end

镜像了上面的 Rust 解法。
It mirrors the Rust solution above.