Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Merges right hand side dictionary into left hand side dictionary. Works on nested dictionaries as well.
- ///
- /// - Parameters:
- /// - lhs: Dictionary you want to merge someting.
- /// - rhs: Merging dictionary.
- /// - Returns: Returns merged dictionary.
- internal func +<Key, Value> (lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value] {
- var result = lhs
- rhs.forEach {
- if let dict = $1 as? [Key: Value] {
- if let exist = result[$0] as? [Key: Value] {
- result[$0] = exist + dict as? Value
- } else {
- result[$0] = dict as? Value
- }
- } else {
- result[$0] = $1
- }
- }
- return result
- }
- /// Appends the right hand side dictionary. Works on nested dictionaries as well
- ///
- /// - Parameters:
- /// - lhs: Dictionary you want to merge someting.
- /// - rhs: Merging dictionary.
- internal func +=<Key, Value> (lhs: inout [Key: Value], rhs: [Key: Value]) {
- // swiftlint:disable:next shorthand_operator
- lhs = lhs + rhs
- }
Add Comment
Please, Sign In to add comment