Skip to content

Instantly share code, notes, and snippets.

@fxm90
fxm90 / Dictionary+PlusAssignment.swift
Last active June 14, 2021 09:53
Combine two dictionaries of same type with custom operator.
extension Dictionary {
/// Combine two dictionaries of same type with `+` operator.
///
/// - Important: When `left` and `right` are having a same key, the value from `right` will override
/// the value from `left`. E.g.
/// ```
/// var left = ["a": 1, "b": 2]
/// let right = ["a": 3, "c": 4]
/// left += right
/// print(left)
@fxm90
fxm90 / Array+PlusAssignment.swift
Last active August 17, 2017 06:40
Append one value of same type to array.
func += <T>(left: inout [T], right: T) {
left.append(right)
}