Skip to content

Commit fa95c6c

Browse files
RogerluoJutho
authored andcommitted
Drop v0.6 and update travis and add support to diff (#7)
* drop v0.6 and update to 1.0 * update travis * add docs to module * add diff * use 0.7 & switch to recursive implementation * add doc string
1 parent cda9e30 commit fa95c6c

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.6
7+
- 0.7
88
- nightly
99
notifications:
1010
email: false

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
julia 0.6
1+
julia 1.0

src/TupleTools.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
__precompile__(true)
1+
"""
2+
Type stable methods for small tuples
3+
"""
24
module TupleTools
35

46
using Base: tuple_type_head, tuple_type_tail, tuple_type_cons, tail, front, setindex
@@ -26,12 +28,7 @@ Base.@pure StaticLength(N::Int) = StaticLength{N}()
2628
Base.@pure Base.:+(::StaticLength{N₁}, ::StaticLength{N₂}) where {N₁,N₂} = StaticLength(N₁+N₂)
2729
Base.@pure Base.:-(::StaticLength{N₁}, ::StaticLength{N₂}) where {N₁,N₂} = StaticLength(max(0,N₁-N₂))
2830

29-
if VERSION < v"0.7.0-DEV.843"
30-
@inline Base.ntuple(f, ::StaticLength{N}) where {N} = ntuple(f, Val{N})
31-
else
32-
@inline Base.ntuple(f, ::StaticLength{N}) where {N} = ntuple(f, Val{N}())
33-
end
34-
31+
@inline Base.ntuple(f, ::StaticLength{N}) where {N} = ntuple(f, Val{N}())
3532
@inline argtail2(a, b, c...) = c
3633

3734
"""
@@ -327,4 +324,13 @@ Inverse permutation of a permutation `p`.
327324
"""
328325
invperm(p::Tuple{Vararg{Int}}) = sortperm(p)
329326

327+
"""
328+
diff(v::Tuple) -> Tuple
329+
330+
Finite difference operator of tuple `v`.
331+
"""
332+
diff(v::Tuple{}) = () # similar to diff([])
333+
diff(v::Tuple{Any}) = ()
334+
diff(v::Tuple) = (v[2]-v[1], diff(Base.tail(v))...)
335+
330336
end # module

test/runtests.jl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
if VERSION < v"0.7.0-DEV.2005"
2-
const Test = Base.Test
3-
end
4-
if VERSION >= v"0.7.0-DEV.3406"
5-
using Random
6-
end
7-
if VERSION < v"0.7.0-DEV.3516"
8-
const argmin = Base.indmin
9-
const argmax = Base.indmax
10-
end
11-
12-
using Test
1+
using Random, Test
132
using TupleTools
143

154
using Base: tail, front
@@ -57,3 +46,5 @@ end
5746
@test @inferred(TupleTools.isperm(t)) == true
5847
@test @inferred(TupleTools.isperm((1,2,1))) == false
5948
@test @inferred(TupleTools.permute(t, t)) == (p[p]...,)
49+
50+
@test @inferred(TupleTools.diff((1, 2, 3))) == (1, 1)

0 commit comments

Comments
 (0)