forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollections.ts
More file actions
26 lines (24 loc) · 718 Bytes
/
collections.ts
File metadata and controls
26 lines (24 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export function makeArray<V>(original: Array<V> | null = null): Array<V> {
if (original) {
let cloned = new Array<V>(original.length);
for (let i = 0, k = original.length; i < k; ++i) unchecked(cloned[i] = original[i]);
return cloned;
}
return new Array<V>();
}
export function makeSet<V>(original: Set<V> | null = null): Set<V> {
if (original) {
let cloned = new Set<V>();
for (let v of original) cloned.add(v);
return cloned;
}
return new Set<V>();
}
export function makeMap<K,V>(original: Map<K,V> | null = null): Map<K,V> {
if (original) {
let cloned = new Map<K,V>();
for (let [k, v] of original) cloned.set(k, v);
return cloned;
}
return new Map<K,V>();
}