[swift-evolution] Lambda function syntax

Pierre Monod-Broca pierre at monod-broca.fr
Wed Dec 23 05:49:50 CST 2015


I like that the closure parameters are inside the closure, to me it makes as much sense as outside. They're the input, so as much in as out.

I have nothing against `in`, but I wouldn't be against a sensible replacement.
I like `=>`, but I'm concerned it might be confused with `->` by beginners in swift.

-- 
Pierre

> Le 23 déc. 2015 à 11:21, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> I have to admit I haven't read the entire thread, so maybe I missed discussion of this.
> 
> I, too, don't like the `params in code` syntax. After a year and a half with Swift, I now remember it, but it still reads funny, and I see new developers struggle with it frequently. I've also used Ruby quite a bit, but I really don't like the `||` syntax there either.
> 
> What I would do is pull the parameters/type signature out of the braces and put a symbol in front of them. For example:
> 
> 	let names = people.map => person { person.name }
> 
> 	database.saveRecord(record) => record, error {
> 		if let record = record {
> 			completionHandler(true)
> 		}
> 		else {
> 			handleError(error!)
> 		}
> 	}
> 
> `=>` is used here merely because it's been discussed upthread; I actually think it's a little too heavy for this role, but I don't have a great replacement immediately at hand.
> 
> A no-parameters closure would not require a `=>`; a bare block would still do there. I suppose the capture list would still go before the parameters, but after the `=>`. Other closure features remain the same—you can still use the `$N` implicit parameters, and you can still use `->` to specify a return value, `()` to surround the parameters, `:` to specify exact types, etc.
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 
> _______________________________________________
> 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/20151223/c50c8979/attachment.html>


More information about the swift-evolution mailing list