[swift-evolution] [Idea] Syntactic sugar for using methods as functions

Anton Zhilin antonyzhilin at gmail.com
Mon Jun 27 16:07:46 CDT 2016


Charlie Monroe via swift-evolution <swift-evolution at ...> writes:

> This will only get you an array of closures:
> 
> let bars = foos.map(Foo.getBar) // [() -> Int, () -> Int, () -> Int]
> bars[0]   // () -> Int
> bars[0]() // 1

Just checked:

struct A {
    func a() -> Int { return 0 }
}
print(A.a.dynamicType)  //=> (A) -> (()) -> Int

Wut?

First of all, (()) -> Int should mean function with one parameter, since 
tuple splat behaviour is going to be removed.

Then, with uncurrying proposal, A.a.dynamicType should be (A) -> Int, 
because both self and other parameters are now passed together.

My guess is that both accepted proposals are still not implemented. Once 
it's done, we will get (A.a)(A()) == 0 and [A(), A()].map(A.a) == [0, 0]



More information about the swift-evolution mailing list