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

Enum "shorter dot" syntax sugar #1183

Closed
dagba opened this issue Aug 27, 2020 · 1 comment
Closed

Enum "shorter dot" syntax sugar #1183

dagba opened this issue Aug 27, 2020 · 1 comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@dagba
Copy link

dagba commented Aug 27, 2020

Hello there! 🖖

I've found the explicitly specifying an enum's name is too boilerplate. So can u please add "shorter dot" syntax sugar?

Example:

enum CompassPoint {
    case north
    case south
    case east
    case west
}

var directionToHead = CompassPoint.west The type of directionToHead is inferred when it’s initialized with one of the possible values of CompassPoint. Once directionToHead is declared as a CompassPoint, you can set it to a different CompassPoint value using a shorter dot syntax:

directionToHead = .east The type of directionToHead is already known, and so you can drop the type when setting its value. This makes for highly readable code when working with explicitly typed enumeration values.

if directionToHead == .east { doSomething() }

@dagba dagba added the feature Proposed language feature that solves one or more problems label Aug 27, 2020
@mateusfccp
Copy link
Contributor

Duplicate of #357.

@lrhn lrhn added the state-duplicate This issue or pull request already exists label Aug 27, 2020
@lrhn lrhn closed this as completed Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants