[swift-evolution] Currying/Partial Application

Jeremy Pereira jeremy.j.pereira at googlemail.com
Thu Oct 6 04:47:27 CDT 2016


You can emulate it with a closure

func myFunc(a: Int, b: Int, c: Int) -> Int { return a + b + c }

let partial = { (b) -> Int in return myFunc(a: 5, b: b, c: 7) }
let ans = partial(6) // 18

It’s not ideal because you lose the argument label, but I think they’re going to fix that one day.

> On 6 Oct 2016, at 01:50, Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Erica’s thread on currying made me remember a (very) early discussion on the topic where currying was being removed temporarily in hopes that partial application could be added back in later with better syntax.
> 
> I would really like to be able to do the following:
> 
> 	let partial = myFunc(a: 5, b: _, c: 7)
> 	let ans = partial(b: 6)
> 
> Thanks,
> Jon
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list