aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
authorSam Wilkins <abdullah_ahmed@brown.edu>2019-04-30 20:41:51 -0400
committerSam Wilkins <abdullah_ahmed@brown.edu>2019-04-30 20:41:51 -0400
commitee31019f719b46db57de486e66158e9600515edd (patch)
treeab197fb9eb1063cb5a91a7ca9e7d8cab2594e7e3 /src/Utils.ts
parent43ed4e7fd2d6120598733e537a301a8f87379239 (diff)
all non-list object field [Copy] implemented
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index c1ad88e2f..d4b6f5377 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -116,4 +116,18 @@ export function returnZero() { return 0; }
export function emptyFunction() { }
-export type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; \ No newline at end of file
+export type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
+
+export type Predicate<K, V> = (entry: [K, V]) => boolean;
+
+export function deepCopy<K, V>(source: Map<K, V>, predicate?: Predicate<K, V>) {
+ let deepCopy = new Map<K, V>();
+ let entries = source.entries(), next = entries.next();
+ while (!next.done) {
+ let entry = next.value;
+ if (!predicate || predicate(entry)) {
+ deepCopy.set(entry[0], entry[1]);
+ }
+ }
+ return deepCopy;
+} \ No newline at end of file