Skip to content

Commit

Permalink
⭐️ Impl: Dictionary+Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Sep 28, 2024
1 parent a0fe50c commit 5322de9
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions ios/Temp/Dictionary+Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Dictionary+Helpers.swift
// react-native-ios-modal
//
// Created by Dominic Go on 9/29/24.
//

import Foundation


public extension Dictionary {

mutating func merge(
withOther otherDict: Self,
shouldOverwriteValues: Bool = true
){
self.merge(otherDict) {
shouldOverwriteValues ? $1 : $0;
};
};

mutating func unwrapAndMerge(
withOther otherDict: Dictionary<Key, Value?>,
shouldOverwriteValues: Bool = true
) {

let filtered = otherDict.compactMapValues { $0 };

self.merge(filtered) {
shouldOverwriteValues ? $1 : $0;
};
};

func merging(
withOther otherDict: Self,
shouldOverwriteValues: Bool = true
) -> Self {
self.merging(otherDict) {
shouldOverwriteValues ? $1 : $0;
};
};

func unwrapBeforeMerging(
withOther otherDict: Dictionary<Key, Value?>,
shouldOverwriteValues: Bool = true
) -> Self {
let filtered = otherDict.compactMapValues { $0 };

return self.merging(filtered) {
shouldOverwriteValues ? $1 : $0;
};
};
};

0 comments on commit 5322de9

Please sign in to comment.