Skip to content

Commit

Permalink
Define halve(::Pairs) (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Aug 7, 2020
1 parent db5f411 commit 5aecb37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/implementations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion test/test_halve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"αβγδϵ"
Expand All @@ -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)
Expand Down

0 comments on commit 5aecb37

Please sign in to comment.