-
Notifications
You must be signed in to change notification settings - Fork 0
/
IsFunction.ts
47 lines (42 loc) · 999 Bytes
/
IsFunction.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
import {
HasTrueResult,
Scalar,
UnaryFunction
} from '@main';
/**
* Determines if variable is of type {@link UnaryFunction}.
*/
export class IsFunction<T> implements Scalar<boolean> {
/**
* Check if function with true result exists.
*/
private readonly hasTrueResult: UnaryFunction<T, boolean>;
/**
* Variable to check.
*/
private readonly maybeFunc: T;
/**
* Ctor.
* @param maybeFunc Variable to check.
* @param hasTrueResult Check if function with true result exists.
*/
constructor(
maybeFunc: T,
hasTrueResult: UnaryFunction<T, boolean> = new HasTrueResult('isFunction')
) {
this.hasTrueResult = hasTrueResult;
this.maybeFunc = maybeFunc;
}
/**
* Type determinant.
*/
public isScalar(): true {
return true;
}
/**
* Get the value.
*/
public value(): boolean {
return this.hasTrueResult.apply(this.maybeFunc);
}
}