[swift-evolution] Tuple conversion and type composition

Andrew Bennett cacoyi at gmail.com
Sat Jan 30 23:14:26 CST 2016

Hi Swift Evolution populace,

I'd like a a way to concatenate tuple types together:

typealias ABCD = (A,B)+(C,D) // Same as (A,B,C,D)

Also a way to allow tuples to be converted to other tuples that are the
same when flattened:

(a,(b,c),d) as ((a,b),(c,d))

This proposal aims to make the minimal changes possible, with the most
familiar syntax, and give tuples this power.
These are things that will be possible after these changes.
Joining two tuples together

let a = (1,2), b = (3,4)let c = join(a, b) // (Int,Int,Int,Int)

Stack like operations on tuples

let (abcde)  = (1,2,3,4,5)let (abcd,e) = pop(abcde)let (abc,d)  =
pop(abcd)let (abce)   = push(abc, e)assert(abce == (1,2,3,5))

Chained ZipSequence

let a = [1,2,3]let b = ["a", "b", "c"]let c = [1.2, 2.3, 3.4]let d =
[nil, nil, 123]let abc = a.zip(b).zip(c).zip(d) //

Turn any function with a callback into one with a promise

func promise<A,B,C>(f: (A + (B->Void)) -> C) -> A -> (C, Promise<B>)

This proposal, and more examples, can be seen in more detail here:


I'll keep this file up to date over the course of the discussion, PRs are

*Related proposals:*

This proposal's use cases relate to at least a few other currently active

   - *Compile-time parameters*
   - *http://thread.gmane.org/gmane.comp.lang.swift.evolution/5240
   - *Contiguous Variables (A.K.A. Fixed Sized Array Type)*
      <http://thread.gmane.org/gmane.comp.lang.swift.evolution/4809> *
*Remove implicit tuple splat behavior from function applications *
      - *http://thread.gmane.org/gmane.comp.lang.swift.evolution/4681

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160131/c86e817c/attachment.html>

More information about the swift-evolution mailing list