File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 55// Created by Théophane Rupin on 3/8/19.
66//
77
8+ public enum SwitchCaseVariableOptionality {
9+ case some
10+ case none
11+ case notOptional
12+ }
13+
814public struct SwitchCaseVariable : Hashable , MetaSwiftConvertible {
915
16+ public let optionality : SwitchCaseVariableOptionality
17+
1018 public let name : String
1119
1220 public var type : TypeIdentifier ?
13-
14- public init ( name: String , as type: TypeIdentifier ? = nil ) {
21+
22+ public init ( optionality: SwitchCaseVariableOptionality = . notOptional, name: String , as type: TypeIdentifier ? = nil ) {
23+ self . optionality = optionality
1524 self . name = name
1625 self . type = type
1726 }
@@ -113,7 +122,15 @@ extension Switch: FunctionBodyMember {}
113122extension SwitchCaseVariable {
114123
115124 public var swiftString : String {
116- return " let \( name) \( type? . swiftString. prefixed ( " as " ) ?? . empty) "
125+ let assignment = " let \( name) \( type? . swiftString. prefixed ( " as " ) ?? . empty) "
126+ switch optionality {
127+ case . some:
128+ return " .some( \( assignment) ) "
129+ case . none:
130+ return " .none "
131+ case . notOptional:
132+ return assignment
133+ }
117134 }
118135}
119136
You can’t perform that action at this time.
0 commit comments