Pairwise iterator

From Introduction · IterTools

using IterTools

for i in partition(1:9, 2, 1)
    @show i
end

# i = (1, 2)
# i = (2, 3)
# i = (3, 4)
# i = (4, 5)
# i = (5, 6)
# i = (6, 7)
# i = (7, 8)
# i = (8, 9)

d = Dict(:a => 1, :b => 2, :c => 3)

for i in partition(d, 2, 1)
    @show i
end

# i = (:a => 1, :b => 2)
# i = (:b => 2, :c => 3)

5 Likes