-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapOf.ts
48 lines (43 loc) · 965 Bytes
/
MapOf.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
41
42
43
44
45
46
47
48
import {
FunctionLike,
FunctionOf,
Mapped,
Scalar,
UnaryFunction
} from '@main';
/**
* Map of iterable and callback.
*/
export class MapOf<Z, K, V> implements Scalar<Map<K, V>> {
/**
* Items.
*/
private readonly entries: Iterable<Z>;
/**
* Function to get key value entry.
*/
private readonly getEntry: UnaryFunction<Z, [K, V]>;
/**
* Ctor.
* @param entries Items.
* @param getEntry Function or standard JavaScript function to get key value entry.
*/
constructor(entries: Iterable<Z>, getEntry: FunctionLike<Z, [K, V]>) {
this.entries = entries;
this.getEntry = new FunctionOf(getEntry);
}
/**
* Type determinant.
*/
public isScalar(): true {
return true;
}
/**
* Gets the value.
*/
public value(): Map<K, V> {
return new Map(
new Mapped(this.entries, this.getEntry)
);
}
}