[swift-evolution] Proposal: Remove implicit tuple splat behavior from function applications

Andrew Bennett cacoyi at gmail.com
Wed Jan 27 17:38:05 CST 2016


I'm for making it clearer, not for removing it.

If I understand correctly we would lose the ability to do this:

func compose<A,B,C>(lhs: A -> B, rhs: B -> C) -> A -> C {

    return { rhs(lhs($0)) }

}

let apply: (Int,Int)->Int = compose(+, rhs: abs)

print("result: ", apply(1,-5)) // prints 4, ie. abs(1 + -5)


It's nice at the moment to be able to do generalised functions on functions
without needing versions for every combination of parameter count.

The biggest use case for me is generics, specifically functions on
functions and testing libraries.


On Thu, Jan 28, 2016 at 6:41 AM, Chris Lattner via swift-evolution <
swift-evolution at swift.org> wrote:

>
> On Jan 27, 2016, at 11:32 AM, Jarod Long <swift at lng.la> wrote:
>
> But failure in this case is a function that takes two arguments, and
> failureStubs is an array of tuples that map to that function's arguments.
> How do the tuple values get mapped to the arguments if not via tuple
> splatting?
>
>
> Ah ok, I was looking at the success case I guess.  You’re right.  In this
> case, instead of :
>
>     failure(failureStubs.removeFirst())
>
> you’d have to write something like this:
>
>     let tmp = failureStubs.removeFirst()
>     failure(tmp.0, tmp.1)
>
> -Chris
>
>
> Jarod
>
> On Jan 27, 2016, at 11:28, Chris Lattner <clattner at apple.com> wrote:
>
> On Jan 27, 2016, at 11:24 AM, swift at lng.la wrote:
>
> Apologies -- I just realized I chose a bad example that isn't actually
> using the feature, but the usage would be here:
>
> if successStubs.count > 0 {
>     success(successStubs.removeFirst())
> }
> else if failureStubs.count > 0 {
>     failure(failureStubs.removeFirst())
> }
>
>
> This isn’t using the feature either.  You are passing a single value
> (returned by removeFirst) as a single argument.  No spat is happening.
>
> -Chris
>
>
>
>
> _______________________________________________
> 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/20160128/2616edf4/attachment.html>


More information about the swift-evolution mailing list