Created
March 27, 2016 10:20
-
-
Save lancy/7e644a8e50deb68a1aec to your computer and use it in GitHub Desktop.
Mutating Generic Enum Issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum List<Element> { | |
| case End | |
| indirect case Node(Element, next: List<Element>) | |
| } | |
| enum ListError: ErrorType { | |
| case EndCannotAppendValue | |
| } | |
| extension List { | |
| mutating func append(value: Element) throws -> List { | |
| guard case .Node(let element) = self else { throw ListError.EndCannotAppendValue } | |
| let next = List.Node(value, next: .End) | |
| // Error: Cannot convert value of type 'List<Element>' to expected argument type 'List<_>' | |
| self = List.Node(element, next: next) | |
| return next | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bad news:
appendfunction can only return a immutable value, which can't be call in chain.