OptionSetType desperately needs a .Empty option

I kinda hate the new OptionSetType stuff. It looks and smells like an array, but it's not an array. Even more annoying, there's not the .Empty value. We used to be able to use .allZeros. Now, for something that wants an option set type, we have to put the confusing [] everywhere.

I would say it “looks and smells” like the Set type from the standard library, which can also be initialised from an ArrayLiteral. If you're making your own OptionSetTypes then feel free to include a .Empty case if you like. Or, if you're determined not to get used to it, even though you're going to see example code involving sets using it all the time, and it fits with the mathematical notation for an empty set, then do something like

func emptyOptionSet<T: OptionSetType>() -> T {
  return []
}

or preferably something like

extension OptionSetType {
  static var EmptySet: Self {
    return []
  }
}

if I could get it to stop crashing playgrounds.

FWIW, if you feel that the [] syntax is too implicit, you might instead use the default initializer for the type, e.g.: SomeOptionSet()


-Chris

OptionSetType desperately needs a .Empty option
 
 
Q