Nope, not really. It’s an open topic for future evolution (see the core team feedback on the Result proposal), and you can create your own APIs to do this on a per-type basis, but those are pretty much your options.
OK. So it turns out it's quite simple boilerplate to add to the enum…
public enum Word
{
case word
indirect case synonym(Word, synonym: String)
var isSynonym: Bool
{
if case .synonym(_, _) = self
{
return true
}
return false
}
}
Thanks Nevin. I rather like this. I have added it to my enum, which is a bit more complex than your example but it really makes coding a lot easier, especially when it involves having to do a switch on the enum case to see whether the subject is either one of several "ordinary" cases (which now all return the same Case) or one of the associated value ones, which now have their individual Cases.
And, for the sake of a few lines of code here, I now have several places where the code is so much easier to read.