Re: [swift-users] for with optional collection?

2017-02-12 Thread Maxim Veksler via swift-users
How about: let c: [Int]? = nil c.map { for e in $0 { print(e) } } // 1 // 2 // 3 Based on https://developer.apple.com/reference/swift/optional/1539476-map#discussion On Thu, Feb 9, 2017 at 11:26 PM Rick Mann via swift-users < swift-users@swift.org> wrote: > Is there any concise way to write

Re: [swift-users] for with optional collection?

2017-02-10 Thread Rick Mann via swift-users
How would you write for x in array as? With parentheses? I like "in?" because it mimics "as?". Sent from my iPhone > On Feb 10, 2017, at 13:57, Jacob Bandes-Storch wrote: > > To me it would seem more logical as "for x in array? { }" — to parallel "for > case let x? in array { }" > > >> O

Re: [swift-users] for with optional collection?

2017-02-10 Thread Jacob Bandes-Storch via swift-users
To me it would seem more logical as "for x in array? { }" — to parallel "for case let x? in array { }" On Fri, Feb 10, 2017 at 1:03 PM, Rick Mann via swift-users < swift-users@swift.org> wrote: > I love the idea of for in? (Or even for? In). You should pitch that to > evolution. > > Sent from my

Re: [swift-users] for with optional collection?

2017-02-10 Thread Rick Mann via swift-users
I love the idea of for in? (Or even for? In). You should pitch that to evolution. Sent from my iPhone > On Feb 10, 2017, at 07:04, Tino Heth <2...@gmx.de> wrote: > > >> Is there any concise way to write the following? >> >> if let collection = someOptionalCollection >> { >>for item in co

Re: [swift-users] for with optional collection?

2017-02-10 Thread Maury Markowitz via swift-users
> On Feb 10, 2017, at 10:04 AM, Tino Heth via swift-users > wrote: > > for i in? test { > print(i) > } > > Imho looks even better, but this would need an extension of the language > itself… Oh, yes please! Please post on evolution. ___ swift-

Re: [swift-users] for with optional collection?

2017-02-10 Thread Tino Heth via swift-users
> Is there any concise way to write the following? > > if let collection = someOptionalCollection > { >for item in collection >{ >} > } I've been thinking about that lately, but haven't had the time to look wether someone on evolution already proposed a "for in?"-loop… Imho the "for

Re: [swift-users] for with optional collection?

2017-02-09 Thread David Hart via swift-users
someOptionalCollection?.forEach { item in } > On 9 Feb 2017, at 22:48, Marco S Hyman via swift-users > wrote: > > >> On Feb 9, 2017, at 1:26 PM, Rick Mann via swift-users >> wrote: >> >> Is there any concise way to write the following? >> >> if let collection = someOptionalCollection >> {

Re: [swift-users] for with optional collection?

2017-02-09 Thread Rick Mann via swift-users
> On Feb 9, 2017, at 13:31 , Saagar Jha wrote: > > for item in someOptionalCollection ?? [] { > item.doSomething() > } > Thanks, this is probably the closest. Sadly I can't seem to test downcasting because Playgrounds just stop working, with no feedback, for this code: class Foo {

Re: [swift-users] for with optional collection?

2017-02-09 Thread Marco S Hyman via swift-users
> On Feb 9, 2017, at 1:26 PM, Rick Mann via swift-users > wrote: > > Is there any concise way to write the following? > > if let collection = someOptionalCollection > { >for item in collection >{ >} > } someOptionalCollection?.map { /* do something with $0 /* } _

Re: [swift-users] for with optional collection?

2017-02-09 Thread Saagar Jha via swift-users
Or even for item in someOptionalCollection ?? [] { item.doSomething() } Saagar Jha > On Feb 9, 2017, at 1:30 PM, Jeff Kelley via swift-users > wrote: > > You can do something like this: > > someOptionalCollection?.forEach { item in > item.doSomething() > } > > Or this: > > (s

Re: [swift-users] for with optional collection?

2017-02-09 Thread Jeff Kelley via swift-users
You can do something like this: someOptionalCollection?.forEach { item in item.doSomething() } Or this: (someOptionalCollection as? [SomeType])?.forEach { item in item.doSomething() } Jeff Kelley slauncha...@gmail.com | @SlaunchaMan | jeffkell

[swift-users] for with optional collection?

2017-02-09 Thread Rick Mann via swift-users
Is there any concise way to write the following? if let collection = someOptionalCollection { for item in collection { } } I can imagine more complicated things, too: if let collection = someOptionalCollection as? [SomeType] { for item in collection { } } It would be nic