I'm beginning to agree that generating properties might not be the best approach, since cases are intended to read like function names.
To give a quick example:
enum Selection {
case range(from: Int, to: Int)
case discreteIndices(in: [Int], inverted: Bool)
}
let selection = Selection.range(from: 1, to: 2)
selection.range?.to // = .some(2)
selection.discreteIndices?.in.first
This clearly has some readability issues.
To provide another example following @anthonylatsis's direction, using a matches
operator based on @Erica_Sadun's previously suggested pattern matching operator:
selection matches .range(from: _, to: let upperBound) // = .some(2)
(selection matches .discreteIndices(let indices, _))?.first
selection matches let .range(a, b) // produces an (a: Int, b: Int)?
It's a bit more verbose, but it still supports optional chaining while keeps the cases' argument labels in context. This could potentially support setters, although this would be in conflict with precedent set by as?
, and is complicated slightly by allowing tuple return values.