Skip to content

Conversation

AnthonyLatsis
Copy link
Contributor

@AnthonyLatsis AnthonyLatsis commented Jul 16, 2018

This proposal is about allowing optional sequences in for-in loops.

var array: [Int]? = nil

for? element in array { ... } // does nothing

array = [1, 2, 3]

for? element in array { ... }
// equivalent to
for element in array! { ... }

https://forums.swift.org/t/another-try-at-allowing-optional-iteration/14376/44

Implementation – swiftlang/swift#19207

@AnthonyLatsis AnthonyLatsis changed the title Optional Iteration [WIP] Optional Iteration Jul 16, 2018
@AnthonyLatsis AnthonyLatsis changed the title [WIP] Optional Iteration Optional Iteration Sep 8, 2018
@AnthonyLatsis
Copy link
Contributor Author

AnthonyLatsis commented Sep 9, 2018

@jrose-apple, is it possible to schedule a review for this?

@jrose-apple
Copy link
Contributor

I'm not on the core team, sorry. I'm not sure if they were waiting for anything else.

@AnthonyLatsis
Copy link
Contributor Author

AnthonyLatsis commented Sep 10, 2018

I see, excuse me then.

cc @jckarter


for? element in array { ... }
// Equivalent to
for element in array! { ... }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would clarify what the syntactic construct is equivalent to in the general case:

if let array2 = array {
  for element in array2 {
    ...
  }
}

This summary suggests that the force-unwrap is part of the behavior of for?, which might mislead someone reading this bit in isolation.

@jckarter
Copy link
Contributor

Once an implementation is ready, we can queue the proposal for review.

@AnthonyLatsis
Copy link
Contributor Author

AnthonyLatsis commented Sep 10, 2018

Once an implementation is ready, we can queue the proposal for review.

Is it necessary for the implementation to be ready for merging (reviewed and approved)? I've got a working draft over here.

@jckarter jckarter self-assigned this Sep 25, 2018
@jckarter jckarter merged commit de85dc7 into swiftlang:master Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants