-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapIterable.ts
40 lines (33 loc) · 886 Bytes
/
MapIterable.ts
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import WrapperIterable from './WrapperIterable'
import './extensions/aggregate'
export default class MapIterable<TKey, TValue> extends WrapperIterable<[TKey, TValue]> {
private _underlyingMap: Map<TKey, TValue>
constructor(map: Map<TKey, TValue>) {
/* istanbul ignore next */
{
super(map)
}
this._underlyingMap = map
}
keys() {
return new WrapperIterable(this._underlyingMap.keys())
}
entries() {
return new WrapperIterable(this._underlyingMap.entries())
}
values() {
return new WrapperIterable(this._underlyingMap.values())
}
has(v: TKey) {
return this._underlyingMap.has(v)
}
get(key: TKey) {
return this._underlyingMap.get(key)
}
convertToObject(this: MapIterable<string, TValue>) {
return this.entries().aggregate({}, (acc: any, [key, value]) => {
acc[key] = value
return acc
})
}
}