diff --git a/Sources/KeyPath.swift b/Sources/KeyPath.swift index 698d07b..1208aad 100644 --- a/Sources/KeyPath.swift +++ b/Sources/KeyPath.swift @@ -4,7 +4,7 @@ import Foundation /// Simple struct used to represent multiple segments of a string. /// This is a utility used to recursively access values in nested dictionaries. -public struct KeyPath { +public struct KeyPath: Hashable { public var segments: [String] public var isEmpty: Bool { return segments.isEmpty } @@ -41,6 +41,18 @@ extension KeyPath: ExpressibleByStringLiteral { } } +extension KeyPath: CustomStringConvertible { + public var description: String { + return segments.joined(separator: ".") + } +} + +public extension KeyPath { + static func + (lhs: KeyPath, rhs: KeyPath) -> KeyPath { + return KeyPath(lhs.description + "." + rhs.description) + } +} + public extension Dictionary where Key == String { subscript(keyPath keyPath: KeyPath) -> Any? { get {