1
+ import type { Predicate } from "@core/unknownutil/type" ;
1
2
import { assert } from "@core/unknownutil/assert" ;
3
+ import { asOptional } from "@core/unknownutil/as/optional" ;
2
4
import { isNumber } from "@core/unknownutil/is/number" ;
3
5
import { isObjectOf } from "@core/unknownutil/is/object-of" ;
4
- import { isTupleOf } from "@core/unknownutil/is/tuple-of" ;
5
- import { isUnionOf } from "@core/unknownutil/is/union-of" ;
6
+ import { isParametersOf } from "@core/unknownutil/is/parameters-of" ;
6
7
7
8
/**
8
9
* Type of `screenpos()` result.
@@ -17,15 +18,12 @@ export type ScreenPos = {
17
18
/**
18
19
* Return true if the value is ScreenPos.
19
20
*/
20
- export function isScreenPos ( x : unknown ) : x is ScreenPos {
21
- const predObj = {
22
- row : isNumber ,
23
- col : isNumber ,
24
- endcol : isNumber ,
25
- curscol : isNumber ,
26
- } ;
27
- return isObjectOf ( predObj ) ( x ) ;
28
- }
21
+ export const isScreenPos : Predicate < ScreenPos > = isObjectOf ( {
22
+ row : isNumber ,
23
+ col : isNumber ,
24
+ endcol : isNumber ,
25
+ curscol : isNumber ,
26
+ } ) ;
29
27
30
28
/**
31
29
* Assert if `x` is ScreenPos by raising an `AssertError` when it's not.
@@ -48,13 +46,9 @@ export type Position = [
48
46
/**
49
47
* Return true if the value is Position.
50
48
*/
51
- export function isPosition ( x : unknown ) : x is Position {
52
- const pred = isUnionOf ( [
53
- isTupleOf ( [ isNumber , isNumber , isNumber , isNumber ] ) ,
54
- isTupleOf ( [ isNumber , isNumber , isNumber , isNumber , isNumber ] ) ,
55
- ] ) ;
56
- return pred ( x ) ;
57
- }
49
+ export const isPosition : Predicate < Position > = isParametersOf (
50
+ [ isNumber , isNumber , isNumber , isNumber , asOptional ( isNumber ) ] as const ,
51
+ ) ;
58
52
59
53
/**
60
54
* Assert if `x` is Position by raising an `AssertError` when it's not.
0 commit comments