Skip to content

Commit

Permalink
Add NTuple(f,n) syntax to construct Tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman committed Jun 20, 2015
1 parent f0e4d37 commit 38a3594
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/implementation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ function concatenate{T<:Tuple, S<:Tuple}(::Type{T}, ::Type{S})
Tuple{T.parameters..., S.parameters...}
end

## Allow constructing Tuples like tuples with NTuple (akin to ntuple)
Base.call(::Type{NTuple}, f, n::Integer) = Tuple{ntuple(f, n)...}


end # module
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ gm = first(methods(g))
@test Types.length(Tuple{Int8, Int16,Vararg{String}}) === 3
@test Types.length(Tuple{Int8, Int16, Int32,Vararg{String}}) === 4
@test Types.length(Tuple{Int8, Int16, Int32, Int64,Vararg{String}}) === 5


# Test NTuple
@test NTuple(i->Val{i}, 1) === Tuple{Val{1}}
@test NTuple(i->Val{i}, 2) === Tuple{Val{1}, Val{2}}
@test NTuple(i->Val{i}, 3) === Tuple{Val{1}, Val{2}, Val{3}}
@test NTuple(i->Val{i}, 4) === Tuple{Val{1}, Val{2}, Val{3}, Val{4}}

0 comments on commit 38a3594

Please sign in to comment.