|
1 |
| -# TupleTools |
| 1 | + |
| 2 | +<a id='TupleTools.jl-1'></a> |
| 3 | + |
| 4 | +# TupleTools.jl |
| 5 | + |
2 | 6 |
|
3 | 7 | [](https://travis-ci.org/jutho/TupleTools.jl)
|
4 | 8 |
|
| 9 | + |
5 | 10 | [](https://coveralls.io/github/jutho/TupleTools.jl?branch=master)
|
6 | 11 |
|
| 12 | + |
7 | 13 | [](http://codecov.io/github/jutho/TupleTools.jl?branch=master)
|
| 14 | + |
| 15 | + |
| 16 | +A bunch of tools for using tuples (mostly homogeneous tuples `NTuple{N}`) as a collection and performing a number of operations with an inferrable result, typically also an `NTuple{M}` with inferrable length `M`. Type inference breaks down if some of the final or intermediate tuples exceed `MAX_TUPLETYPE_LEN`, meaning inference typically works up to output tuples of length `13` or `14`. Inference also breaks down for most methods in case of inhomogeneous tuples. |
| 17 | + |
| 18 | + |
| 19 | +<a id='Types-1'></a> |
| 20 | + |
| 21 | +## Types |
| 22 | + |
| 23 | +<a id='TupleTools.StaticLength' href='#TupleTools.StaticLength'>#</a> |
| 24 | +**`TupleTools.StaticLength`** — *Type*. |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +``` |
| 29 | +struct StaticLength{N} end |
| 30 | +``` |
| 31 | + |
| 32 | +Like `Val{N}`, `StaticLength` can be used to construct a tuple of inferrable length using `ntuple(f, StaticLength(N))`. Here, `StaticLength(N)` creates `StaticLength{N}()` using a `Base.@pure` constructor. Furthermore, one can add and subtract `StaticLength` objects, such that |
| 33 | + |
| 34 | +``` |
| 35 | +StaticLength(N₁) + StaticLength(N₂) == StaticLength(N₁+N₂) |
| 36 | +``` |
| 37 | + |
| 38 | +and |
| 39 | + |
| 40 | +``` |
| 41 | +StaticLength(N₁) - StaticLength(N₂) == StaticLength(max(0, N₁-N₂)) |
| 42 | +``` |
| 43 | + |
| 44 | + |
| 45 | +<a id='Functions-1'></a> |
| 46 | + |
| 47 | +## Functions |
| 48 | + |
| 49 | +<a id='TupleTools.tail2' href='#TupleTools.tail2'>#</a> |
| 50 | +**`TupleTools.tail2`** — *Function*. |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +``` |
| 55 | +tail2(t::Tuple) -> ::Tuple |
| 56 | +``` |
| 57 | + |
| 58 | +Returns a tuple with the first two elements stripped, equivalent to `tail(tail(t))` |
| 59 | + |
| 60 | +<a id='TupleTools.unsafe_tail' href='#TupleTools.unsafe_tail'>#</a> |
| 61 | +**`TupleTools.unsafe_tail`** — *Function*. |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +``` |
| 66 | +unsafe_tail(t::Tuple) -> ::Tuple |
| 67 | +``` |
| 68 | + |
| 69 | +Returns a tuple with the first element stripped, similar to `tail(t)`, but does not error on an empty tuple (instead returning an empty tuple again). An empty tuple is thus the fixed point of this function. |
| 70 | + |
| 71 | +<a id='TupleTools.unsafe_front' href='#TupleTools.unsafe_front'>#</a> |
| 72 | +**`TupleTools.unsafe_front`** — *Function*. |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +``` |
| 77 | +unsafe_front(t::Tuple) -> ::Tuple |
| 78 | +``` |
| 79 | + |
| 80 | +Returns a tuple with the last element stripped, similar to `front(t)`, but does not error on an empty tuple (instead returning an empty tuple again). An empty tuple is thus the fixed point of this function. |
| 81 | + |
| 82 | +<a id='TupleTools.getindices' href='#TupleTools.getindices'>#</a> |
| 83 | +**`TupleTools.getindices`** — *Function*. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +``` |
| 88 | +getindices(t::Tuple, I::Tuple{Vararg{Int}}) -> ::Tuple |
| 89 | +``` |
| 90 | + |
| 91 | +Get the indices `t[i] for i in I`, again as tuple. |
| 92 | + |
| 93 | +<a id='TupleTools.vcat' href='#TupleTools.vcat'>#</a> |
| 94 | +**`TupleTools.vcat`** — *Function*. |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +``` |
| 99 | +vcat(args...) -> ::Tuple |
| 100 | +``` |
| 101 | + |
| 102 | +Like `vcat` for tuples, concatenates a combination of tuple arguments and non-tuple arguments into a single tuple. Only works one level deep, i.e. tuples in tuples are not expanded. |
| 103 | + |
| 104 | +<a id='TupleTools.deleteat' href='#TupleTools.deleteat'>#</a> |
| 105 | +**`TupleTools.deleteat`** — *Function*. |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | +``` |
| 110 | +deleteat(t::Tuple, i::Int) -> ::Tuple |
| 111 | +deleteat(t::Tuple, I::Tuple{Vararg{Int}}) -> ::Tuple |
| 112 | +``` |
| 113 | + |
| 114 | +Delete the element at location `i` in `t`; if a list `I` of indices is specified (again as a tuple), the elements of these different positions are deleted. |
| 115 | + |
| 116 | +<a id='TupleTools.insertat' href='#TupleTools.insertat'>#</a> |
| 117 | +**`TupleTools.insertat`** — *Function*. |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +``` |
| 122 | +insertat(t::Tuple, i::Int, t2::Tuple) -> ::Tuple |
| 123 | +``` |
| 124 | + |
| 125 | +Insert the elements of tuple t2 at location `i` in `t`, i.e. the output tuple will look as (t[1:i-1]..., t2..., t[i+1:end]). Note that element `t[i]` is deleted. See `splice` if you would also like to return `t[i]` |
| 126 | + |
| 127 | +<a id='TupleTools.sort' href='#TupleTools.sort'>#</a> |
| 128 | +**`TupleTools.sort`** — *Function*. |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +``` |
| 133 | +sort(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple |
| 134 | +``` |
| 135 | + |
| 136 | +Sorts the tuple `t`. |
| 137 | + |
| 138 | +<a id='TupleTools.sortperm' href='#TupleTools.sortperm'>#</a> |
| 139 | +**`TupleTools.sortperm`** — *Function*. |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | +``` |
| 144 | +sortperm(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple |
| 145 | +``` |
| 146 | + |
| 147 | +Computes a tuple that contains the permutation required to sort `t`. |
| 148 | + |
| 149 | +<a id='TupleTools.invperm' href='#TupleTools.invperm'>#</a> |
| 150 | +**`TupleTools.invperm`** — *Function*. |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | +``` |
| 155 | +invperm(p::NTuple{N,Int}) -> ::NTuple{N,Int} |
| 156 | +``` |
| 157 | + |
| 158 | +Inverse permutation of a permutation `p`. |
| 159 | + |
| 160 | +<a id='TupleTools.permute' href='#TupleTools.permute'>#</a> |
| 161 | +**`TupleTools.permute`** — *Function*. |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +``` |
| 166 | +permute(t::Tuple, p) -> ::Tuple |
| 167 | +``` |
| 168 | + |
| 169 | +Permute the elements of tuple `t` according to the permutation in `p`. |
| 170 | + |
0 commit comments