[swift-evolution] Stdlib closure argument labels and parameter names

Patrick Smith pgwsmith at gmail.com
Mon Jun 27 22:21:01 CDT 2016


Side question: is there going to be any situation where I’m iterating through a sequence/collection that I wouldn’t want to always use `lazy`? Is `lazy` *always* going to be more efficient than the array-creating defaults when the result is iterated?

For instance, something much better than this terrible syntax:

for a in sequence where .filter({ $0 > 5 }).map({ $0 * 2 })  {
  print(a)
}

It would be up to the compiler what calls it turns that into, possibly it could make a certain whitelist of transformations (filter, map) as efficient as using `for … where` or `guard` today? Or it could simply make use of `lazy`.

`for` is already hiding ‘magic’ by calling `makeIterator()`, why can’t it do more ‘magic’, especially since `lazy` is a member of `Sequence` just like `makeIterator()`.

Anyway, something for the future after Swift 3.0.

Patrick

> On 28 Jun 2016, at 1:58 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Yeah, kicking myself over that. Can't Swift remind me to add `lazy` 
> by emitting a warning or something? I keep assuming certain things are
> naturally lazy and then have to go back and de-eagerize.

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


More information about the swift-evolution mailing list