diff --git a/src/implementations.jl b/src/implementations.jl index e7bbbfa..90ba3f1 100644 --- a/src/implementations.jl +++ b/src/implementations.jl @@ -159,6 +159,11 @@ function halve(xs::DictLike) return (left, right) end +function halve(xs::Iterators.Pairs) + left, right = halve(keys(xs)) + return Iterators.Pairs(values(xs), left), Iterators.Pairs(values(xs), right) +end + function halve(xs::AbstractString) offset = firstindex(xs) - 1 mid = thisind(xs, (lastindex(xs) - offset) ÷ 2 + offset) diff --git a/test/test_halve.jl b/test/test_halve.jl index 7222564..6f09225 100644 --- a/test/test_halve.jl +++ b/test/test_halve.jl @@ -21,6 +21,10 @@ permutedims(reshape(1:24, 2, 3, 4), (3, 1, 2)) permutedims(reshape(1:24, 2, 3, 4), (3, 2, 1)) OffsetArray(1:15, -1) OffsetArray(reshape(1:15, 3, 5), -1:1, 0:4) +pairs(1:10) +pairs(1:11) +pairs(reshape(1:6, 2, 3)) +pairs(adjoint(reshape(1:6, 2, 3))) "abcde" "abcdef" "αβγδϵ" @@ -43,7 +47,8 @@ Iterators.filter(isodd, 1:6) Iterators.flatten([1:3, 4:5]) product(1:3, 1:4) product(1:3, 1:4, 1:5) -product(1:3, (1, 2), (a=1, b=2)) +product(pairs(1:10), pairs(1:11)) +product(1:3, pairs(1:11), (1, 2), (a=1, b=2)) partition(1:10, 1) partition(1:10, 2) partition(1:10, 3)