# \#tuple

**URL:** https://discourse.julialang.org/tag/tuple/138.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Type stable \`mapreduce\` on Tuples](https://discourse.julialang.org/t/type-stable-mapreduce-on-tuples/136978)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 6\
**Last updated:** [May 5, 2026, 2:52pm UTC](https://discourse.julialang.org/t/type-stable-mapreduce-on-tuples/136978 "2026-05-05T14:52:43Z")

</div>

Hello, I want to apply this very simple example of mapreduce involving eachindex on two tuples function test\_standard(x::Tuple, y::Tuple) length(x) == length(y) || throw(ArgumentError("Input tuples must have the sam…

---

## [Extract unique types between two Tuples at compile time](https://discourse.julialang.org/t/extract-unique-types-between-two-tuples-at-compile-time/135476)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 10\
**Last updated:** [February 9, 2026, 7:20pm UTC](https://discourse.julialang.org/t/extract-unique-types-between-two-tuples-at-compile-time/135476 "2026-02-09T19:20:56Z")

</div>

Hello, I have two Tuples x and y containing objects of different types. I now want to create at compile time a list containing only the unique types. I have tried this function test2(x::T1, y::T2) where {T1 \<: Tuple, T…

---

## [\`Tuple\` of \`Union\` or \`Union\` of \`Tuple\`?](https://discourse.julialang.org/t/tuple-of-union-or-union-of-tuple/134311)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 8\
**Last updated:** [December 4, 2025, 10:28am UTC](https://discourse.julialang.org/t/tuple-of-union-or-union-of-tuple/134311 "2025-12-04T10:28:12Z")

</div>

I want to annotate a type-unstable variable with a type-parameter constraint to improve the chance of union splitting during compilation. In general, should I do Tuple of Union or Union of Tuple? For example, which of t…

---

## [Why can't a tuple of types have an abstract type with Type selectors?](https://discourse.julialang.org/t/why-cant-a-tuple-of-types-have-an-abstract-type-with-type-selectors/134036)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 7\
**Last updated:** [November 23, 2025, 11:12am UTC](https://discourse.julialang.org/t/why-cant-a-tuple-of-types-have-an-abstract-type-with-type-selectors/134036 "2025-11-23T11:12:10Z")

</div>

julia\> 1 isa Int true julia\> (1,) isa Tuple{Int} true julia\> Int isa Type{Int} true julia\> (Int,) isa Tuple{Type{Int}} # ??? false And how does dispatch work if this doesn’t work for method signatures as tuple types? …

---

## [Coupling finite\`Union\` with \`T\` in \`NTuple{2, T} where {T}\`](https://discourse.julialang.org/t/coupling-finite-union-with-t-in-ntuple-2-t-where-t/133567)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 7\
**Last updated:** [November 11, 2025, 10:48am UTC](https://discourse.julialang.org/t/coupling-finite-union-with-t-in-ntuple-2-t-where-t/133567 "2025-11-11T10:48:15Z")

</div>

We know that for UnionAll of Tuple that uses the same type parameter (e.g., T) for all the element types (in default) requires the element types to be the same concrete type: julia\> f1(a::Tuple{T, T}) where {T\<:Real} = …

---

## [Type instability with (fairly) simple Tuples](https://discourse.julialang.org/t/type-instability-with-fairly-simple-tuples/133304)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 7\
**Last updated:** [October 20, 2025, 12:25pm UTC](https://discourse.julialang.org/t/type-instability-with-fairly-simple-tuples/133304 "2025-10-20T12:25:03Z")

</div>

Should I expect the following to be type-stable? I think the types are inferrable in principle, but maybe the Tuple-of-Pairs structure is just too ‘complicated’? julia\> using Cthulhu julia\> function foo(t::Pair{Symbol,…

---

## [Broadcast a function returning multiple values](https://discourse.julialang.org/t/broadcast-a-function-returning-multiple-values/131314)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 15\
**Last updated:** [August 5, 2025, 7:49am UTC](https://discourse.julialang.org/t/broadcast-a-function-returning-multiple-values/131314 "2025-08-05T07:49:53Z")

</div>

If I understand it correctly, a function that looks like returning multiple values actually returns a Tuple of the values and therefore the result of broadcasting on the function is an array of the Tuples: function f1(x…

---

## [How to change dims data from NT or T to ::OutDims for YAXArrays.DAT.OutputCube](https://discourse.julialang.org/t/how-to-change-dims-data-from-nt-or-t-to-outdims-for-yaxarrays-dat-outputcube/125700)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 0\
**Last updated:** [February 9, 2025, 9:17am UTC](https://discourse.julialang.org/t/how-to-change-dims-data-from-nt-or-t-to-outdims-for-yaxarrays-dat-outputcube/125700 "2025-02-09T09:17:41Z")

</div>

Hi guys, I am new to Julia, and wants to run a function which is like: outcubes = mapCube(TEMYax, (incubes...,); selected\_models=selected\_models, forcing\_vars=forcing.variables, output\_v…

---

## [How to make splat, map and tuples be efficient](https://discourse.julialang.org/t/how-to-make-splat-map-and-tuples-be-efficient/125653)

<div class="topic-metadata">

**Author:** [@garazha-ilya](https://discourse.julialang.org/u/garazha-ilya)\
**Replies:** 3\
**Last updated:** [February 7, 2025, 7:08pm UTC](https://discourse.julialang.org/t/how-to-make-splat-map-and-tuples-be-efficient/125653 "2025-02-07T19:08:29Z")

</div>

Generally I want to make f(g("a"), g("c"), g("k")) with f(map(g, \["a","c","k"\])...) be efficient and don’t generate allocations. And I started experimenting, by creating 3 functions: function foo\_tuple(a,b,c) …

---

## [Unassigned type parameters in \`UnionAll\` of \`Tuple\` do not refer to concrete types in edge cases](https://discourse.julialang.org/t/unassigned-type-parameters-in-unionall-of-tuple-do-not-refer-to-concrete-types-in-edge-cases/125217)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 5\
**Last updated:** [January 30, 2025, 8:14am UTC](https://discourse.julialang.org/t/unassigned-type-parameters-in-unionall-of-tuple-do-not-refer-to-concrete-types-in-edge-cases/125217 "2025-01-30T08:14:13Z")

</div>

Consider a simple example where I define a type alias for (non-empty) Tuple: julia\> const MyTuple1{T, N} = Tuple{T, Vararg{T, N}} Tuple{T, Vararg{T, N}} where {T, N} Even when the type parameter T is not assigned, the U…

---

## [Efficient tuple concatenation](https://discourse.julialang.org/t/efficient-tuple-concatenation/5398)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 16\
**Last updated:** [January 17, 2025, 7:42pm UTC](https://discourse.julialang.org/t/efficient-tuple-concatenation/5398 "2025-01-17T19:42:51Z")

</div>

I was needing a way to concatenate an undefined number of tuples. I came up with tuplejoin(t1::Tuple, t2::Tuple, t3...) = tuplejoin((t1..., t2...), t3...) tuplejoin(t::Tuple) = t This works julia\> tuplejoin((1,2),(3,4…

---

## [Function arguments](https://discourse.julialang.org/t/function-arguments/61717)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 37\
**Last updated:** [December 20, 2024, 4:56pm UTC](https://discourse.julialang.org/t/function-arguments/61717 "2024-12-20T16:56:59Z")

</div>

Is it possible to pass a named tuple to a function and have the components available as variables without explicitly specifying them as arguments. f( X ) = A + B X = (A=1,B=2) f( X ) output : 3 Background: I have ab…

---

## [Sort tuple](https://discourse.julialang.org/t/sort-tuple/110730)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 11\
**Last updated:** [December 8, 2024, 9:56pm UTC](https://discourse.julialang.org/t/sort-tuple/110730 "2024-12-08T21:56:14Z")

</div>

Any reason this shouldn’t work? julia\> sort((1,2,3)) ERROR: MethodError: no method matching sort(::Tuple{Int64, Int64, Int64})

---

## [Tuple{Vararg{T, N}} where N \>= 1](https://discourse.julialang.org/t/tuple-vararg-t-n-where-n-1/121644)

<div class="topic-metadata">

**Author:** [@croberts](https://discourse.julialang.org/u/croberts)\
**Replies:** 9\
**Last updated:** [October 23, 2024, 7:35pm UTC](https://discourse.julialang.org/t/tuple-vararg-t-n-where-n-1/121644 "2024-10-23T19:35:39Z")

</div>

It can be extremely convenient to dispatch on the types of arguments in a tuple, creating an alias for tuples of a type. However, a zero-length tuple will match a Vararg Tuple of any type, which can create issues with d…

---

## [Memory allocations when performing operation on Tuple of structs](https://discourse.julialang.org/t/memory-allocations-when-performing-operation-on-tuple-of-structs/121276)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 9\
**Last updated:** [October 15, 2024, 10:18am UTC](https://discourse.julialang.org/t/memory-allocations-when-performing-operation-on-tuple-of-structs/121276 "2024-10-15T10:18:31Z")

</div>

Hello, I’m facing a memory allocation problem on an apparently simple case. I have the following struct struct MyStruct{T1\<:AbstractMatrix, T2} data::T1 other::T2 end where data is a matrix and other is someth…

---

## [Requiring a NamedTuple instead of just a tuple to return multiple columns from a function for DataFrames.jl seem unintuitive. Discussion](https://discourse.julialang.org/t/requiring-a-namedtuple-instead-of-just-a-tuple-to-return-multiple-columns-from-a-function-for-dataframes-jl-seem-unintuitive-discussion/119691)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 3\
**Last updated:** [September 22, 2024, 1:06pm UTC](https://discourse.julialang.org/t/requiring-a-namedtuple-instead-of-just-a-tuple-to-return-multiple-columns-from-a-function-for-dataframes-jl-seem-unintuitive-discussion/119691 "2024-09-22T13:06:28Z")

</div>

I tried to read the transform doc for DataFrames.jl and I have to say it’s tough going. But I think it contains lots of info. The situation I want to discuss is actually documented in the doc but the question, how do I …

---

## [When to use Tuples instead of Vectors?](https://discourse.julialang.org/t/when-to-use-tuples-instead-of-vectors/119109)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 16\
**Last updated:** [September 6, 2024, 3:42pm UTC](https://discourse.julialang.org/t/when-to-use-tuples-instead-of-vectors/119109 "2024-09-06T15:42:49Z")

</div>

Hello, I’m developing QuantumToolbox.jl for simulating quantum systems in Julia. Everything is based on the QuantumObject constructor, which is currently defined as follows struct QuantumObject{MT\<:AbstractArray,ObjTyp…

---

## [Converting Vector to Tuple seems not optimal](https://discourse.julialang.org/t/converting-vector-to-tuple-seems-not-optimal/115989)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 11\
**Last updated:** [June 22, 2024, 7:01am UTC](https://discourse.julialang.org/t/converting-vector-to-tuple-seems-not-optimal/115989 "2024-06-22T07:01:31Z")

</div>

Hi there, I am working on improving the memory allocation performance of my code and in learning about how to do so I came across the fact that tuples are much cheaper to store that vectors. For this reason I was trying…

---

## [Array of tuples](https://discourse.julialang.org/t/array-of-tuples/11435)

<div class="topic-metadata">

**Author:** [@jcrbloch](https://discourse.julialang.org/u/jcrbloch)\
**Replies:** 17\
**Last updated:** [June 20, 2024, 9:39am UTC](https://discourse.julialang.org/t/array-of-tuples/11435 "2024-06-20T09:39:27Z")

</div>

I have an array A of tuples Array{TupleFloat64,Float64},1}, but am not able to make two arrays out of this like: I1 = A\[:\]\[1\] I2 = A\[:\]\[2 even though I can access the individual elements with A\[i\]\[j\]

---

## [Advice for Higher Order Functions on Tuples](https://discourse.julialang.org/t/advice-for-higher-order-functions-on-tuples/115509)

<div class="topic-metadata">

**Author:** [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Replies:** 6\
**Last updated:** [June 12, 2024, 6:55am UTC](https://discourse.julialang.org/t/advice-for-higher-order-functions-on-tuples/115509 "2024-06-12T06:55:50Z")

</div>

I have a package where I’m operating on lists of types, and I need everything to compile away. I have succeeded in doing so by using these two functions: using Tricks """ Utility function which generates a list of expr…

---

## [Declare tuple type of arbitrary length](https://discourse.julialang.org/t/declare-tuple-type-of-arbitrary-length/115199)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 0\
**Last updated:** [June 4, 2024, 9:41pm UTC](https://discourse.julialang.org/t/declare-tuple-type-of-arbitrary-length/115199 "2024-06-04T21:41:45Z")

</div>

Is there any way I can declare a type for my dictionary with a tuple of the same element type but of arbitrary length? For example I can currently do this: d = Dict{Tuple{Int, Int}, String}() d\[(1, 2)\] = "a" and get a…

---

## [Type inference when just making a tuple](https://discourse.julialang.org/t/type-inference-when-just-making-a-tuple/115071)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 6\
**Last updated:** [June 2, 2024, 9:16pm UTC](https://discourse.julialang.org/t/type-inference-when-just-making-a-tuple/115071 "2024-06-02T21:16:42Z")

</div>

Hello, I’m seeing some type instabilities in my code. I saw that converting a vector into a tuple generates instabilities. Here a very simple example using Test function prova(vec) return Tuple(vec) end T = Floa…

---

## [Tuple to DateTime](https://discourse.julialang.org/t/tuple-to-datetime/114066)

<div class="topic-metadata">

**Author:** [@DTL](https://discourse.julialang.org/u/DTL)\
**Replies:** 4\
**Last updated:** [May 10, 2024, 6:27am UTC](https://discourse.julialang.org/t/tuple-to-datetime/114066 "2024-05-10T06:27:50Z")

</div>

I’m processing a CSV file where I have a couple of years of recordings, there are several readings per hour, and I’m summing them altogether to get a total per day. I get the data into a dataframe ok. julia\> df 32047×…

---

## [Compiler recursion limit](https://discourse.julialang.org/t/compiler-recursion-limit/112698)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 10\
**Last updated:** [April 17, 2024, 11:52pm UTC](https://discourse.julialang.org/t/compiler-recursion-limit/112698 "2024-04-17T23:52:55Z")

</div>

I’ve written some recursive code that compiles away due to (I believe) constant propagation. However, I’m afraid that if I run the code on a larger problem I will hit a compiler recursion limit and it will no longer comp…

---

## [\[ANN\] OptimalSortingNetworks: Sort small collections efficiently and with good type inference](https://discourse.julialang.org/t/ann-optimalsortingnetworks-sort-small-collections-efficiently-and-with-good-type-inference/105544)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 14\
**Last updated:** [February 25, 2024, 6:59pm UTC](https://discourse.julialang.org/t/ann-optimalsortingnetworks-sort-small-collections-efficiently-and-with-good-type-inference/105544 "2024-02-25T18:59:05Z")

</div>

OptimalSortingNetworks (OSN for short) is being registered. Use it to sort small tuples or vectors: julia\> using OptimalSortingNetworks julia\> sorted(\[10, 5, 7, 9\]) 4-element Vector{Int64}: 5 7 9 10 julia\> sort…

---

## [Type instability possibly due to variable playing role of input and output](https://discourse.julialang.org/t/type-instability-possibly-due-to-variable-playing-role-of-input-and-output/110178)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 11\
**Last updated:** [February 15, 2024, 12:43pm UTC](https://discourse.julialang.org/t/type-instability-possibly-due-to-variable-playing-role-of-input-and-output/110178 "2024-02-15T12:43:11Z")

</div>

EDIT: contrary to the title, I have come to the conclusion that the problem lies elsewhere (see post below). Unless this contradicts etiquette, I will not modify the original title, nor the original question below. NEW …

---

## [Behavior of \`fieldtypes\` applied to \`Tuple{...}\`](https://discourse.julialang.org/t/behavior-of-fieldtypes-applied-to-tuple/110030)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 2\
**Last updated:** [February 10, 2024, 6:42pm UTC](https://discourse.julialang.org/t/behavior-of-fieldtypes-applied-to-tuple/110030 "2024-02-10T18:42:50Z")

</div>

Here is the docstring for fieldtypes: fieldtypes(T::Type) The declared types of all fields in a composite DataType T as a tuple. Examples ≡≡≡≡≡≡≡≡≡≡ julia\> struct Foo x::Int64 y::String e…

---

## [Type intersection with \`NTuple{len,Any}\`](https://discourse.julialang.org/t/type-intersection-with-ntuple-len-any/109765)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [February 6, 2024, 2:30pm UTC](https://discourse.julialang.org/t/type-intersection-with-ntuple-len-any/109765 "2024-02-06T14:30:53Z")

</div>

Problem: say I have a type T such that T \<: Tuple, and len, a nonnegative Int value. I want the intersection of T and NTuple{len,Any}. Is it possible to solve the above correctly and exactly? I have three candidate solu…

---

## [How to strip tuple type of the element types](https://discourse.julialang.org/t/how-to-strip-tuple-type-of-the-element-types/109664)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 6\
**Last updated:** [February 3, 2024, 9:09pm UTC](https://discourse.julialang.org/t/how-to-strip-tuple-type-of-the-element-types/109664 "2024-02-03T21:09:57Z")

</div>

I want a function taking a type T\<:Tuple type and returning S\<:Tuple type such that T\<:S and the element types are stripped from the input, but with preserved length information. Desired behavior examples: f(Tuple{}) =…

---

## [Counting the number of appearance of Tuples in a Vector](https://discourse.julialang.org/t/counting-the-number-of-appearance-of-tuples-in-a-vector/108901)

<div class="topic-metadata">

**Author:** [@blociss](https://discourse.julialang.org/u/blociss)\
**Replies:** 8\
**Last updated:** [January 17, 2024, 7:13pm UTC](https://discourse.julialang.org/t/counting-the-number-of-appearance-of-tuples-in-a-vector/108901 "2024-01-17T19:13:48Z")

</div>

Let vec = \[(“A”, “B”), (“A”, “C”), (“A”, “D”), (“B”, “C”), (“B”, “D”)\] be a vector. I want to count the number of appearance of each element at each step in the for loop. function count\_occurrences(vec) vect = \[\] …

[Next page](https://discourse.julialang.org/tag/tuple/138.md?match_all_tags=true&page=1&tags%5B%5D=tuple)
