Skip to content

Propose Pack Destructuring & Pack Splitting #2796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update punctuations
  • Loading branch information
Oguz Yuksel committed Apr 21, 2025
commit ee1e019a3fc592a156aa9613229a32af3cd569de
6 changes: 3 additions & 3 deletions proposals/NNNN-pack-destructuring-and-pack-splitting.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Review: ([pitch](https://forums.swift.org/t/pitch-pack-destructuring-pack-splitting/79388))

## Introduction
Swifts variadic generics story (SE‑0393 Parameter Packs and SE‑0408 Pack Iteration) unlocks powerful abstractions over arbitrary arities. However, two missing features—recursive decomposition of packs in patterns and split‑expansion of packs at call sites—force library authors into brittle workarounds like fixed‑arity overloads or type erasure. This proposal completes the variadic‑generic toolbox by introducing:
Swift's variadic generics story (SE‑0393 "Parameter Packs" and SE‑0408 "Pack Iteration") unlocks powerful abstractions over arbitrary arities. However, two missing features—recursive decomposition of packs in patterns and split‑expansion of packs at call sites—force library authors into brittle workarounds like fixed‑arity overloads or type erasure. This proposal completes the variadic‑generic toolbox by introducing:

1. **Pack Destructuring in Patterns** – extract `head` and `tail` from a variadic tuple in a `let` or `switch` pattern.
2. **Pack Splitting in Calls** – feed a single parameter‐pack expansion into separate head + tail parameters at call sites.
Expand All @@ -16,7 +16,7 @@ These additions eliminate boilerplate, remove arbitrary arity limits, and enable

## Motivation
- **No recursive pack decomposition**: We cannot peel off the first element of a parameter pack at compile time.
- **Fixed‑arity overloads & limits**: Combines `zip` (up to 10 overloads) and SwiftUIs `TupleView` (10 views max) are symptomatic workarounds.
- **Fixed‑arity overloads & limits**: Combine's `zip` (up to 10 overloads) and SwiftUI's `TupleView` (10 views max) are symptomatic workarounds.
- **Type erasure** sacrifices compile‑time safety and incurs runtime costs (`[AnyPublisher]`).
- **Goal**: Give library authors a first‐class, type‑safe, zero‑overhead mechanism to recurse over arbitrary variadic tuples.

Expand Down Expand Up @@ -181,4 +181,4 @@ struct Zip<repeat each S>: Publisher {
2. [SE‑0408: Pack Iteration](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0408-pack-iteration.md) – Enables iteration over packs.

## Conclusion
By adding pack destructuring in patterns and pack splitting in calls, this proposal fills the last gaps in Swifts variadic‑generic capabilities. Library authors can now write truly recursive, zero‑overhead abstractions without fixed arity limits or type erasure, while preserving source and ABI compatibility.
By adding pack destructuring in patterns and pack splitting in calls, this proposal fills the last gaps in Swift's variadic‑generic capabilities. Library authors can now write truly recursive, zero‑overhead abstractions without fixed arity limits or type erasure, while preserving source and ABI compatibility.