diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49249c2..c6a88dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,9 @@ jobs: env: JULIA_NUM_THREADS: 4 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: file: lcov.info test-nightly: diff --git a/Project.toml b/Project.toml index e6e3f1f..016cfbd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,12 +1,15 @@ name = "TupleTools" uuid = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6" authors = ["Jutho Haegeman"] -version = "1.4.3" +version = "1.5.0" [deps] [compat] julia = "1" +Aqua = "0.8" +Random = "1" +Test = "1" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" diff --git a/src/TupleTools.jl b/src/TupleTools.jl index 2ef8ec3..9fa9a98 100644 --- a/src/TupleTools.jl +++ b/src/TupleTools.jl @@ -316,6 +316,15 @@ end _permute(t::NTuple{N,Any}, p::NTuple{N,Int}) where {N} = getindices(t, p) _permute(t::NTuple{N,Any}, p) where {N} = ntuple(n -> t[p[n]], StaticLength(N)) +""" + circshift(t::NTuple{N,Any}, i::Int) -> ::NTuple{N,Any} + +Circularly shift the elements of tuple `t` by `i` positions. +""" +function circshift(t::NTuple{N,Any}, i::Int) where {N} + return ntuple(n -> t[mod1(n - i, N)], StaticLength(N)) +end + """ isperm(p) -> ::Bool @@ -373,4 +382,14 @@ diff(v::Tuple{}) = () # similar to diff([]) diff(v::Tuple{Any}) = () diff(v::Tuple) = (v[2] - v[1], diff(Base.tail(v))...) +""" + indexin(a::Tuple, b::Tuple) + +Return a tuple containing the first indices in `b` of the elements of `a`. If an element +of `a` is not in `b`, then the corresponding index will be `nothing`. +""" +function indexin(a::Tuple, b::Tuple) + return ntuple(i -> findfirst(==(a[i]), b), length(a)) +end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index e5b6339..26fb4ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -78,6 +78,7 @@ using Base: tail, front @test @inferred(TupleTools.isperm(t)) == true @test @inferred(TupleTools.isperm((1, 2, 1))) == false @test @inferred(TupleTools.permute(t, t)) == (p[p]...,) + @test @inferred(TupleTools.circshift(t, 3)) == tuple(circshift(p, 3)...) @test @inferred(TupleTools.vcat()) == () @test @inferred(TupleTools.diff(())) == () @@ -85,11 +86,11 @@ using Base: tail, front @test @inferred(TupleTools.diff((1, 2, 3))) == (1, 1) @test TupleTools.sort((2, 1, 3.0)) === (1, 2, 3.0) + @test TupleTools.indexin(TupleTools.getindices(t, (1, 2, 3)), t) == (1, 2, 3) end @testset "TupleTools quality assurance with Aqua" begin using Aqua Aqua.test_all(TupleTools; - project_toml_formatting=(VERSION >= v"1.9"), unbound_args=false) end