[swift-evolution] Tuple accessor shorthand

Radosław Pietruszewski radexpl at gmail.com
Fri Dec 18 14:46:20 CST 2015


I think this proposal: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003373.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003373.html> would also solve this problem

as you’d be able to do .map(.0), and AFAICT it will still be unambiguous.

— Radek

> On 18 Dec 2015, at 16:30, Alexandre Lopoukhine via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello everyone,
> 
> To tie into the discussion of shorthands for “map", here’s something that I think is worth considering:
> 
> Skipping the motivation (mostly, I’m on a mission to eliminate the $ character in my functional code), here’s a function definition:
> 
> func first<A,B>(tuple: (A,B)) -> A {
>    return tuple.0
> }
> 
> Having functions like this transforms
> 
> pairArray.map({$0.0})
> 
> into
> 
> pairArray.map(first)
> 
> This is not ideal, as it pollutes the global space, and there would need to be tons of those for various tuple sizes.
> 
> Here’s an alternative:
> 
> pairArray.map(().0)
> 
> I think that this makes the intent pretty clear, as well as non-conflicting with anything in the language.
> 
> What do you all think?
> 
> — Sasha
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list