Skip to content

Commit

Permalink
Homogenize behaviour of map over tuples when one is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz committed Mar 18, 2017
1 parent 2364390 commit 82422e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ end
# n argument function
heads(ts::Tuple...) = map(t -> t[1], ts)
tails(ts::Tuple...) = map(tail, ts)
map(f, ::Tuple{}, ts::Tuple...) = ()
map(f, ::Tuple{}...) = ()
function map(f, t1::Tuple, t2::Tuple, ts::Tuple...)
@_inline_meta
(f(heads(t1, t2, ts...)...), map(f, tails(t1, t2, ts...)...)...)
Expand Down
5 changes: 4 additions & 1 deletion test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ begin
@test map(foo, (1,2), (1,2)) === (2,4)
@test map(foo, (1,2,3,4), (1,2,3,4)) === (2,4,6,8)
@test map(foo, longtuple, longtuple) === ntuple(i->2i,20)
@test_throws BoundsError map(foo, (), (1,))
@test_throws BoundsError map(foo, (1,), ())

# n arguments
@test map(foo, (), (), ()) === ()
@test map(foo, (), (1,2,3), (1,2,3)) === ()
@test map(foo, (1,), (1,), (1,)) === (3,)
@test map(foo, (1,2), (1,2), (1,2)) === (3,6)
@test map(foo, (1,2,3,4), (1,2,3,4), (1,2,3,4)) === (3,6,9,12)
@test map(foo, longtuple, longtuple, longtuple) === ntuple(i->3i,20)
@test_throws BoundsError map(foo, (), (1,), (1,))
@test_throws BoundsError map(foo, (1,), (1,), ())
end

## comparison ##
Expand Down

0 comments on commit 82422e8

Please sign in to comment.