-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScalarOf.ts
44 lines (39 loc) · 880 Bytes
/
ScalarOf.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
import {
Scalar,
ScalarLike,
ToValue,
UnaryFunction
} from '@main';
/**
* Scalar of different possible inputs.
*/
export class ScalarOf<T> implements Scalar<T> {
/**
* Value.
*/
private readonly val: ScalarLike<T>;
/**
* Function to convert scalar-like types to their respective values.
*/
private readonly toValue: UnaryFunction<ScalarLike<T>, T>;
/**
* Ctor.
* @param value Scalar, function that returns value, or value.
*/
constructor(value: ScalarLike<T>, toValue: UnaryFunction<ScalarLike<T>, T> = new ToValue()) {
this.val = value;
this.toValue = toValue;
}
/**
* Type determinant.
*/
public isScalar(): true {
return true;
}
/**
* Gets the value.
*/
public value(): T {
return this.toValue.apply(this.val);
}
}