Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deriving collections of enum cases #114

Merged
merged 2 commits into from
Jan 7, 2018

Conversation

jtbandes
Copy link
Contributor

swift-evolution discussion thread (other related threads are linked in the proposal).

Rendered Markdown.

@dabrahams dabrahams changed the title Proposal for deriving collections of enum cases Deriving collections of enum cases Feb 9, 2016
@davidask
Copy link

This is a big one, and i gather a lot of people want this. Hoping to see this taken on!

@CodaFi
Copy link
Contributor

CodaFi commented Oct 7, 2016

I'm concerned that this proposal does not address the issue of differently-versioned cases in enums. For an enum like this

public enum QoSClass {
  @available(OSX 10.10, iOS 8.0, *)
  case background

  @available(OSX 10.10, iOS 8.0, *)
  case utility

  @available(OSX 10.10, iOS 8.0, *)
  case `default`

  @available(OSX 10.10, iOS 8.0, *)
  case userInitiated

  @available(OSX 10.10, iOS 8.0, *)
  case userInteractive

  case unspecified
}

Should the derived conformance look like this?

public static var allCases: [QoSClass] {
    if #available(OSX 10.10, iOS 8.0, *) {
      return [
        QoSClass.background,
        QoSClass.utility,
        QoSClass.`default`,
        QoSClass.userInitiated,
        QoSClass.userInteractive,
        QoSClass.unspecified,
      ]
    } else {
      return [ QoSClass.unspecified ]
    }
}

@CodaFi
Copy link
Contributor

CodaFi commented Oct 7, 2016

Moreover, do deprecated cases show up in this list?

@DougGregor
Copy link
Member

DougGregor commented Jan 26, 2017

I'm closing out PRs for proposals that are out of scope for Swift 4 stage 1. When we open up the process to the point where this proposal can be in scope, please re-open the pull request.

@DougGregor DougGregor closed this Jan 26, 2017
@kdawgwilk
Copy link

Is it possible this might fall into the scope of Swift 4 stage 2 now that priorities have been shuffled?

@jtbandes
Copy link
Contributor Author

jtbandes commented Mar 1, 2017

I asked for some clarification about this on Twitter: https://twitter.com/jtbandes/status/834633693138350080

It sounds like it's potentially feasible to do with existing metadata. I've also seen it said that proposals that come with a full or partial implementation are more likely to be accepted 😉 So perhaps if I get some time I'll look at what it would take to add this.

@DougGregor
Copy link
Member

I'll bring it up with the full core team, but because this is purely additive, I don't think it meets the Swift 4 stage 2 criteria.

@DougGregor
Copy link
Member

Yeah, this is purely additive, and doesn't meet the Swift 4 stage 2 criteria.

@louisdh
Copy link

louisdh commented Oct 13, 2017

Can this pull request be re-opened for Swift 5? 🙏

@tkremenek
Copy link
Member

This can be considered for Swift 5 as long as a potential proposal has an implementation.

@CodaFi
Copy link
Contributor

CodaFi commented Oct 17, 2017

I have an implementation I would be willing to put up here.

// @jtbandes

@tkremenek
Copy link
Member

@CodaFi @jtbandes re-opened

@AttilaTheFun
Copy link

Awesome, so glad to see the ball rolling on this!

@jtbandes
Copy link
Contributor Author

jtbandes commented Dec 30, 2017

Hi all, sorry for the long delay here. I've pushed a revised proposal with feedback incorporated from recent discussions. @DougGregor / @tkremenek, please advise if you see this as reviewable in its current form. @CodaFi's example implementation still stands, although it will need to be updated to match the naming choice in the final proposal, and to use associatedtype.

@CodaFi
Copy link
Contributor

CodaFi commented Dec 30, 2017

Excellent. I'll rebase and update my branch this evening.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Looks great!

@DougGregor DougGregor merged commit 591ddf4 into swiftlang:master Jan 7, 2018
@jtbandes jtbandes deleted the case-enumerable branch January 7, 2018 23:08
johnno1962 pushed a commit to DoubleSpeak/swift-evolution that referenced this pull request Mar 18, 2018
* Proposal for deriving collections of enum cases

* Make the derived implementation opt-in
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.

9 participants