Skip to content

Instantly share code, notes, and snippets.

@ollieatkinson
Last active December 26, 2020 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ollieatkinson/8624aff80a038bf7853d40e67f8870b5 to your computer and use it in GitHub Desktop.
Save ollieatkinson/8624aff80a038bf7853d40e67f8870b5 to your computer and use it in GitHub Desktop.
AnyDictionary
protocol AnyDictionary: Collection {
associatedtype Key: Hashable
associatedtype Keys
associatedtype Value
associatedtype Values
associatedtype Index
var keys: Keys { get }
var values: Values { get }
subscript(key: Key) -> Value? { get set }
subscript(key: Key, default defaultValue: @escaping @autoclosure () -> Value) -> Value { get set }
func index(forKey: Key) -> Index?
mutating func updateValue(_ value: Value, forKey key: Key) -> Value?
mutating func merge<S>(_ other: S, uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows where S : Sequence, S.Element == (Key, Value)
mutating func merge(_ other: [Key : Value], uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows
func merging<S>(_ other: S, uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows -> [Key : Value] where S : Sequence, S.Element == (Key, Value)
func merging(_ other: [Key : Value], uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows -> [Key : Value]
mutating func remove(at index: Index) -> Element
mutating func removeValue(forKey key: Key) -> Value?
mutating func removeAll(keepingCapacity keepCapacity: Bool)
}
extension Dictionary: AnyDictionary { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment