# Tuples with default values idea

**URL:** <https://forums.swift.org/t/tuples-with-default-values-idea/70841>\
**Category:** Pitches\
**Tags:** tuple\
**Created:** [March 22, 2024, 1:32pm UTC](https://forums.swift.org/t/tuples-with-default-values-idea/70841 "2024-03-22T13:32:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [March 22, 2024, 1:32pm UTC](https://forums.swift.org/t/tuples-with-default-values-idea/70841/1 "2024-03-22T13:32:56Z")

</div>

Got this rough idea of allowing default values in tuples:

```swift
typealias T = (Int, Double, String = "")
T(1, 2) // ✅

func foo(_ v: (Int, Double, String = "")) {}
foo((1, 2)) // ✅

typealias R = (x: Int, y: Double = 2, z: String)
R(x: 1, z: "3") // ✅

func foo(_ v: (x: Int, y: Double = 2, z: String)) {}
foo((x: 1, z: "3")) // ✅

```

Worth having this in Swift?

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [March 22, 2024, 1:41pm UTC](https://forums.swift.org/t/tuples-with-default-values-idea/70841/2 "2024-03-22T13:41:24Z")

</div>

My general thinking around tuples is that when you start doing things like assigning names to them (`typealias T = ...`) or trying to reach for other behavior to add to them, it's really just time to make it a dedicated `struct`.

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [March 22, 2024, 2:21pm UTC](https://forums.swift.org/t/tuples-with-default-values-idea/70841/3 "2024-03-22T14:21:38Z")

</div>

The tuple may be provided by the API and the API author may not need to give it a typealias name or an added functionality. OTOH the user of this API may have such a need, and he or she can't change the tuple to a struct.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [March 22, 2024, 2:31pm UTC](https://forums.swift.org/t/tuples-with-default-values-idea/70841/4 "2024-03-22T14:31:28Z")

</div>

> [@tera](#):
>
> Got this rough idea of allowing default values in tuples:

Fun fact: default arguments used to be part of the tuple's _type_ in the Swift 2 days, when functions would semantically always have a single input value, which could be a tuple. This caused no end of trouble!

However, you can probably do what you want with a macro. Have the expansion emit a function that takes the parameters with defaults and forms a tuple value from those arguments. Or even just write that function by hand.
