<commit_before>//
//  DictionaryExtensions.swift
//  SwiftHelpSet
//
//  Created by <NAME> on 8/9/16.
//  Copyright © 2016 dalu93. All rights reserved.
//

import Foundation

extension Dictionary {
    
    /**
     Creates a new dictionary instance by adding a set of dictionaries
     
     - parameter dictionaries: Set of dictionaries of the same type
     
     - returns: Sum of all the dictionaries
     */
    public static func byAdding<K,V>(dictionaries: [[K:V]]) -> [K:V] {
        var dictionarySum: [K:V] = [:]
        dictionaries.forEach {
            dictionarySum += $0
        }
        
        return dictionarySum
    }
    
    public subscript(key: Key, or value: Value) -> Value {
        get { return self[key] ?? value }
        
        set { self[key] = newValue }
    }
}

/**
 Adds the element of the right dictionary to the left dictionary

 - Note: If a right dictionary's key exists on the left dictionary, the value will be
        overwritten
 - parameter left:  A dictionary
 - parameter right: An another dictionary
 */
public func +=<K,V>(inout left: [K:V], right: [K:V]) {
    for (key, value) in right {
        left[key] = value
    }
}

/**
 Creates a new `Dictionary` instance that is the result of the 
 `lhs += rhs` operation.
 
 - Note:    the `rhs` values have the priority and they will override the `lhs` values
            for the same key.
 
 - parameter lhs: A `Dictionary`
 - parameter rhs: The other `Dictionary`
 <commit_msg>Revert "Dictionary custom subscript"<commit_after>//
//  DictionaryExtensions.swift
//  SwiftHelpSet
//
//  Created by <NAME> on 8/9/16.
//  Copyright © 2016 dalu93. All rights reserved.
//

import Foundation

extension Dictionary {
    
    /**
     Creates a new dictionary instance by adding a set of dictionaries
     
     - parameter dictionaries: Set of dictionaries of the same type
     
     - returns: Sum of all the dictionaries
     */
    public static func byAdding<K,V>(dictionaries: [[K:V]]) -> [K:V] {
        var dictionarySum: [K:V] = [:]
        dictionaries.forEach {
            dictionarySum += $0
        }
        
        return dictionarySum
    }
}

/**
 Adds the element of the right dictionary to the left dictionary

 - Note: If a right dictionary's key exists on the left dictionary, the value will be
        overwritten
 - parameter left:  A dictionary
 - parameter right: An another dictionary
 */
public func +=<K,V>(inout left: [K:V], right: [K:V]) {
    for (key, value) in right {
        left[key] = value
    }
}

/**
 Creates a new `Dictionary` instance that is the result of the 
 `lhs += rhs` operation.
 
 - Note:    the `rhs` values have the priority and they will override the `lhs` values
            for the same key.
 
 - parameter lhs: A `Dictionary`
 - parameter rhs: The other `Dictionary`
 
{'fraction_non_alphanumeric': 0.10194690265486726, 'fraction_numerical': 0.007787610619469027, 'mean_word_length': 2.3483412322274884, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6072335', 'n_tokens_mistral': 847, 'n_tokens_neox': 805, 'n_words': 317}