in today’s episode of things that really ought to work in swift, but simply don’t:
struct MyApplicationSpecificDictionary
{
private
var table:[Key: [Element]]
private
init(table:[Key: [Element]])
{
self.table = table
}
}
extension MyApplicationSpecificDictionary
{
subscript(key:Key) -> [Element]
{
_read
{
yield self.table[key, default: []]
}
_modify
{
yield &self.table[key, default: []]
}
}
}
extension MyApplicationSpecificDictionary:ExpressibleByDictionaryLiteral
{
init(dictionaryLiteral:(Key, [Element])...)
{
self.init(table: .init(dictionaryLiteral: dictionaryLiteral))
}
}
error: cannot pass array of type '(Key, [Element])...' as variadic
arguments of type '(Key, [Element])'
arghh!!!!
so for now, i really only need empty dictionary literals, so i can get away with
extension MyApplicationSpecificDictionary:ExpressibleByDictionaryLiteral
{
init(dictionaryLiteral:(Key, Never)...)
{
self.init(table: [:])
}
}
but, it really should be easier to define these sorts of specializations for Array
and Dictionary
without giving up on literal syntax. surely there must be a better way?