@fncts/typelevel 0.0.3 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Check.d.ts +3 -3
- package/HKT.d.ts +142 -179
- package/_cjs/HKT.cjs +1 -16
- package/_cjs/HKT.cjs.map +1 -1
- package/_mjs/HKT.mjs +1 -16
- package/_mjs/HKT.mjs.map +1 -1
- package/_src/Check.ts +3 -3
- package/_src/HKT.ts +141 -309
- package/package.json +1 -1
package/Check.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare namespace Check {
|
|
|
27
27
|
/**
|
|
28
28
|
* @tsplus type fncts.Check.Extends
|
|
29
29
|
*/
|
|
30
|
-
type Extends<A, B> = [A] extends [
|
|
30
|
+
type Extends<A, B> = [A] extends [B] ? unknown : never;
|
|
31
31
|
/**
|
|
32
32
|
* @tsplus type fncts.Check.IsUnion
|
|
33
33
|
*/
|
|
@@ -39,11 +39,11 @@ export declare namespace Check {
|
|
|
39
39
|
/**
|
|
40
40
|
* @tsplus type fncts.Check.IsLiteral
|
|
41
41
|
*/
|
|
42
|
-
type IsLiteral<A extends string | number> = Not<Extends<string, A> | Extends<number, A>>;
|
|
42
|
+
type IsLiteral<A extends string | number | boolean> = Not<Extends<string, A> | Extends<number, A> | Extends<boolean, A>>;
|
|
43
43
|
/**
|
|
44
44
|
* @tsplus type fncts.Check.IsStruct
|
|
45
45
|
*/
|
|
46
|
-
type IsStruct<A> = Extends<keyof A, string> & Not<IsUnion<A>>;
|
|
46
|
+
type IsStruct<A> = Check.Extends<keyof A, string> & Check.Not<Check.IsUnion<A>>;
|
|
47
47
|
/**
|
|
48
48
|
* @tsplus type fncts.Check.HaveSameLength
|
|
49
49
|
*/
|
package/HKT.d.ts
CHANGED
|
@@ -1,186 +1,149 @@
|
|
|
1
1
|
import type * as Union from "./Union.js";
|
|
2
|
-
export interface HKT {
|
|
3
|
-
readonly K?: unknown;
|
|
4
|
-
readonly Q?: unknown;
|
|
5
|
-
readonly W?: unknown;
|
|
6
|
-
readonly X?: unknown;
|
|
7
|
-
readonly I?: unknown;
|
|
8
|
-
readonly S?: unknown;
|
|
9
|
-
readonly R?: unknown;
|
|
10
|
-
readonly E?: unknown;
|
|
11
|
-
readonly A?: unknown;
|
|
12
|
-
readonly type?: unknown;
|
|
13
|
-
readonly index?: unknown;
|
|
14
|
-
readonly variance: {
|
|
15
|
-
readonly K?: HKT.Variance;
|
|
16
|
-
readonly Q?: HKT.Variance;
|
|
17
|
-
readonly W?: HKT.Variance;
|
|
18
|
-
readonly X?: HKT.Variance;
|
|
19
|
-
readonly I?: HKT.Variance;
|
|
20
|
-
readonly S?: HKT.Variance;
|
|
21
|
-
readonly R?: HKT.Variance;
|
|
22
|
-
readonly E?: HKT.Variance;
|
|
23
|
-
readonly A?: HKT.Variance;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
2
|
export declare namespace HKT {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
readonly S: "_";
|
|
87
|
-
readonly R: "_";
|
|
88
|
-
readonly E: "_";
|
|
89
|
-
readonly A: "_";
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
export interface FCoE<F> extends HKT {
|
|
93
|
-
readonly type: FK<F, this["K"], this["Q"], this["W"], this["X"], this["I"], this["S"], this["R"], this["E"], this["A"]>;
|
|
94
|
-
readonly variance: {
|
|
95
|
-
readonly K: "_";
|
|
96
|
-
readonly Q: "_";
|
|
97
|
-
readonly W: "_";
|
|
98
|
-
readonly X: "_";
|
|
99
|
-
readonly I: "_";
|
|
100
|
-
readonly S: "_";
|
|
101
|
-
readonly R: "_";
|
|
102
|
-
readonly E: "+";
|
|
103
|
-
readonly A: "_";
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
export interface FContraR<F> extends HKT {
|
|
107
|
-
readonly type: FK<F, this["K"], this["Q"], this["W"], this["X"], this["I"], this["S"], this["R"], this["E"], this["A"]>;
|
|
108
|
-
readonly variance: {
|
|
109
|
-
readonly K: "_";
|
|
110
|
-
readonly Q: "_";
|
|
111
|
-
readonly W: "_";
|
|
112
|
-
readonly X: "_";
|
|
113
|
-
readonly I: "_";
|
|
114
|
-
readonly S: "_";
|
|
115
|
-
readonly R: "-";
|
|
116
|
-
readonly E: "_";
|
|
117
|
-
readonly A: "_";
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
export type ParamName = "K" | "Q" | "W" | "X" | "I" | "S" | "R" | "E" | "A";
|
|
121
|
-
export type Kind<F extends HKT, C, K, Q, W, X, I, S, R, E, A> = F extends {
|
|
122
|
-
readonly type: unknown;
|
|
123
|
-
} ? (F & {
|
|
124
|
-
readonly K: OrFix<C, "K", K>;
|
|
125
|
-
readonly Q: OrFix<C, "Q", Q>;
|
|
126
|
-
readonly W: OrFix<C, "W", W>;
|
|
127
|
-
readonly X: OrFix<C, "X", X>;
|
|
128
|
-
readonly I: OrFix<C, "I", I>;
|
|
129
|
-
readonly S: OrFix<C, "S", S>;
|
|
130
|
-
readonly R: OrFix<C, "R", R>;
|
|
131
|
-
readonly E: OrFix<C, "E", E>;
|
|
132
|
-
readonly A: A;
|
|
133
|
-
})["type"] : FK<F, K, Q, W, X, I, S, R, E, A>;
|
|
134
|
-
export type Infer<F extends HKT, C, N extends ParamName | "C", K> = [K] extends [
|
|
135
|
-
Kind<F, C, infer K, infer Q, infer W, infer X, infer I, infer S, infer R, infer E, infer A>
|
|
136
|
-
] ? N extends "C" ? C : N extends "K" ? K : N extends "Q" ? Q : N extends "W" ? W : N extends "X" ? X : N extends "I" ? I : N extends "S" ? S : N extends "R" ? R : N extends "E" ? E : N extends "A" ? A : never : never;
|
|
137
|
-
export interface Lows {
|
|
138
|
-
"-": unknown;
|
|
139
|
-
"+": never;
|
|
140
|
-
_: any;
|
|
141
|
-
}
|
|
142
|
-
export type Low<F extends HKT, N extends ParamName> = F["variance"][N] extends Variance ? Lows[F["variance"][N]] : never;
|
|
143
|
-
export interface Mixes<P extends ReadonlyArray<unknown>> {
|
|
144
|
-
"-": P extends [any] ? P[0] : P extends [any, any] ? P[0] & P[1] : P extends [any, any, any] ? P[0] & P[1] & P[2] : P extends [any, any, any, any] ? P[0] & P[1] & P[2] & P[3] : P extends [any, any, any, any, any] ? P[0] & P[1] & P[2] & P[3] & P[4] : Union.IntersectionOf<P[number]>;
|
|
145
|
-
"+": P[number];
|
|
146
|
-
_: P[0];
|
|
147
|
-
}
|
|
148
|
-
export type Mix<F extends HKT, N extends ParamName, P extends ReadonlyArray<unknown>> = F["variance"][N] extends Variance ? Mixes<P>[F["variance"][N]] : P[0];
|
|
149
|
-
export type OrNever<K> = unknown extends K ? never : K;
|
|
150
|
-
export type MixStruct<F extends HKT, N extends ParamName, X, Y> = F["variance"][N] extends "_" ? X : F["variance"][N] extends "+" ? Y[keyof Y] : F["variance"][N] extends "-" ? Union.IntersectionOf<{
|
|
151
|
-
[k in keyof Y]: OrNever<Y[k]>;
|
|
152
|
-
}[keyof Y]> : X;
|
|
153
|
-
export interface Intros<A, B> {
|
|
154
|
-
"-": B;
|
|
155
|
-
"+": B;
|
|
156
|
-
_: A;
|
|
157
|
-
}
|
|
158
|
-
export type Intro<F extends HKT, N extends ParamName, A, B> = F["variance"][N] extends Variance ? Intros<A, B>[F["variance"][N]] : A;
|
|
3
|
+
const F: unique symbol;
|
|
4
|
+
type F = typeof F;
|
|
5
|
+
const K: unique symbol;
|
|
6
|
+
type K = typeof K;
|
|
7
|
+
const Q: unique symbol;
|
|
8
|
+
type Q = typeof Q;
|
|
9
|
+
const W: unique symbol;
|
|
10
|
+
type W = typeof W;
|
|
11
|
+
const X: unique symbol;
|
|
12
|
+
type X = typeof X;
|
|
13
|
+
const I: unique symbol;
|
|
14
|
+
type I = typeof I;
|
|
15
|
+
const S: unique symbol;
|
|
16
|
+
type S = typeof S;
|
|
17
|
+
const R: unique symbol;
|
|
18
|
+
type R = typeof R;
|
|
19
|
+
const E: unique symbol;
|
|
20
|
+
type E = typeof E;
|
|
21
|
+
const A: unique symbol;
|
|
22
|
+
type A = typeof A;
|
|
23
|
+
const T: unique symbol;
|
|
24
|
+
type T = typeof T;
|
|
25
|
+
const Ix: unique symbol;
|
|
26
|
+
type Ix = typeof Ix;
|
|
27
|
+
const C: unique symbol;
|
|
28
|
+
type C = typeof C;
|
|
29
|
+
type _K<X extends HKT> = X extends {
|
|
30
|
+
[K]?: () => infer K;
|
|
31
|
+
} ? K : never;
|
|
32
|
+
type _Q<X extends HKT> = X extends {
|
|
33
|
+
[Q]?: (_: infer Q) => void;
|
|
34
|
+
} ? Q : never;
|
|
35
|
+
type _W<X extends HKT> = X extends {
|
|
36
|
+
[W]?: () => infer W;
|
|
37
|
+
} ? W : never;
|
|
38
|
+
type _X<X extends HKT> = X extends {
|
|
39
|
+
[X]?: () => infer X;
|
|
40
|
+
} ? X : never;
|
|
41
|
+
type _I<X extends HKT> = X extends {
|
|
42
|
+
[I]?: (_: infer I) => void;
|
|
43
|
+
} ? I : never;
|
|
44
|
+
type _S<X extends HKT> = X extends {
|
|
45
|
+
[S]?: () => infer S;
|
|
46
|
+
} ? S : never;
|
|
47
|
+
type _R<X extends HKT> = X extends {
|
|
48
|
+
[R]?: (_: infer R) => void;
|
|
49
|
+
} ? R : never;
|
|
50
|
+
type _E<X extends HKT> = X extends {
|
|
51
|
+
[E]?: () => infer E;
|
|
52
|
+
} ? E : never;
|
|
53
|
+
type _A<X extends HKT> = [X] extends [{
|
|
54
|
+
[A]?: () => infer A;
|
|
55
|
+
}] ? A : never;
|
|
56
|
+
type _Ix<X extends HKT> = X extends {
|
|
57
|
+
[Ix]?: infer Ix;
|
|
58
|
+
} ? Ix : never;
|
|
59
|
+
type IndexFor<X extends HKT, K> = X extends {
|
|
60
|
+
[Ix]?: infer Ix;
|
|
61
|
+
} ? Ix : K;
|
|
159
62
|
/**
|
|
160
|
-
*
|
|
63
|
+
* @tsplus type fncts.Kind
|
|
161
64
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
[
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
[
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
65
|
+
type Kind<F extends HKT, K, Q, W, X, I, S, R, E, A> = F & {
|
|
66
|
+
[F]?: F;
|
|
67
|
+
[K]?: () => K;
|
|
68
|
+
[Q]?: (_: Q) => void;
|
|
69
|
+
[W]?: () => W;
|
|
70
|
+
[X]?: () => X;
|
|
71
|
+
[I]?: (_: I) => void;
|
|
72
|
+
[S]?: () => S;
|
|
73
|
+
[R]?: (_: R) => void;
|
|
74
|
+
[E]?: () => E;
|
|
75
|
+
[A]?: () => A;
|
|
76
|
+
} extends {
|
|
77
|
+
[T]?: infer X;
|
|
78
|
+
} ? X : {
|
|
79
|
+
[F]?: F;
|
|
80
|
+
[K]?: () => K;
|
|
81
|
+
[Q]?: (_: Q) => void;
|
|
82
|
+
[W]?: () => W;
|
|
83
|
+
[X]?: () => X;
|
|
84
|
+
[I]?: (_: I) => void;
|
|
85
|
+
[S]?: () => S;
|
|
86
|
+
[R]?: (_: R) => void;
|
|
87
|
+
[E]?: () => E;
|
|
88
|
+
[A]?: () => A;
|
|
89
|
+
};
|
|
181
90
|
/**
|
|
182
|
-
* @tsplus
|
|
91
|
+
* @tsplus type fncts.Typeclass
|
|
183
92
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
93
|
+
interface Typeclass<F extends HKT> {
|
|
94
|
+
[HKT.F]?: F;
|
|
95
|
+
}
|
|
96
|
+
type ParamName = "K" | "Q" | "W" | "X" | "I" | "S" | "R" | "E" | "A";
|
|
97
|
+
type Mix<N extends ParamName, P extends ReadonlyArray<unknown>> = VarianceToMix<P>[ParamToVariance[N]];
|
|
98
|
+
type MixStruct<N extends ParamName, X, Y> = ParamToVariance[N] extends "_" ? X : ParamToVariance[N] extends "+" ? Y[keyof Y] : ParamToVariance[N] extends "-" ? Union.IntersectionOf<{
|
|
99
|
+
[K in keyof Y]: OrNever<Y[K]>;
|
|
100
|
+
}[keyof Y]> : X;
|
|
101
|
+
type Intro<N extends ParamName, A, B> = VarianceToIntro<A, B>[ParamToVariance[N]];
|
|
102
|
+
type Low<N extends ParamName> = VarianceToLow[ParamToVariance[N]];
|
|
103
|
+
type Infer<F extends HKT, N extends ParamName, K> = [K] extends [
|
|
104
|
+
Kind<F, infer K, infer Q, infer W, infer X, infer I, infer S, infer R, infer E, infer A>
|
|
105
|
+
] ? N extends "K" ? K : N extends "Q" ? Q : N extends "W" ? W : N extends "X" ? X : N extends "I" ? I : N extends "S" ? S : N extends "R" ? R : N extends "E" ? E : N extends "A" ? A : never : never;
|
|
106
|
+
type ErasedKind<F extends HKT> = HKT.Kind<F, any, any, any, any, any, any, any, any, any>;
|
|
107
|
+
}
|
|
108
|
+
export interface HKT {
|
|
109
|
+
[HKT.F]?: HKT;
|
|
110
|
+
[HKT.K]?: () => unknown;
|
|
111
|
+
[HKT.Q]?: (_: never) => void;
|
|
112
|
+
[HKT.W]?: () => unknown;
|
|
113
|
+
[HKT.X]?: () => unknown;
|
|
114
|
+
[HKT.I]?: (_: never) => void;
|
|
115
|
+
[HKT.S]?: () => unknown;
|
|
116
|
+
[HKT.R]?: (_: never) => void;
|
|
117
|
+
[HKT.E]?: () => unknown;
|
|
118
|
+
[HKT.A]?: () => unknown;
|
|
119
|
+
[HKT.T]?: unknown;
|
|
120
|
+
[HKT.Ix]?: unknown;
|
|
121
|
+
}
|
|
122
|
+
interface VarianceToMix<P extends ReadonlyArray<unknown>> {
|
|
123
|
+
"-": P extends [any] ? P[0] : P extends [any, any] ? P[0] & P[1] : P extends [any, any, any] ? P[0] & P[1] & P[2] : P extends [any, any, any, any] ? P[0] & P[1] & P[2] & P[3] : P extends [any, any, any, any, any] ? P[0] & P[1] & P[2] & P[3] & P[4] : Union.IntersectionOf<P[number]>;
|
|
124
|
+
"+": P[number];
|
|
125
|
+
_: P[0];
|
|
126
|
+
}
|
|
127
|
+
interface VarianceToIntro<A, B> {
|
|
128
|
+
"-": B;
|
|
129
|
+
"+": B;
|
|
130
|
+
_: A;
|
|
131
|
+
}
|
|
132
|
+
interface VarianceToLow {
|
|
133
|
+
"-": unknown;
|
|
134
|
+
"+": never;
|
|
135
|
+
_: any;
|
|
136
|
+
}
|
|
137
|
+
interface ParamToVariance {
|
|
138
|
+
K: "_";
|
|
139
|
+
Q: "-";
|
|
140
|
+
W: "+";
|
|
141
|
+
X: "+";
|
|
142
|
+
I: "_";
|
|
143
|
+
S: "_";
|
|
144
|
+
R: "-";
|
|
145
|
+
E: "+";
|
|
146
|
+
A: "+";
|
|
186
147
|
}
|
|
148
|
+
declare type OrNever<K> = unknown extends K ? never : K;
|
|
149
|
+
export {};
|
package/_cjs/HKT.cjs
CHANGED
|
@@ -4,23 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.HKT = void 0;
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
8
7
|
var HKT;
|
|
9
8
|
exports.HKT = HKT;
|
|
10
9
|
|
|
11
|
-
(function (HKT) {
|
|
12
|
-
/*
|
|
13
|
-
* Instance util
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @tsplus macro identity
|
|
18
|
-
*/
|
|
19
|
-
function instance(_) {
|
|
20
|
-
// @ts-expect-error: typelevel utility
|
|
21
|
-
return _;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
HKT.instance = instance;
|
|
25
|
-
})(HKT || (exports.HKT = HKT = {}));
|
|
10
|
+
(function (HKT) {})(HKT || (exports.HKT = HKT = {}));
|
|
26
11
|
//# sourceMappingURL=HKT.cjs.map
|
package/_cjs/HKT.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HKT.cjs","names":["HKT"
|
|
1
|
+
{"version":3,"file":"HKT.cjs","names":["HKT"],"sources":["../esm/HKT.js"],"sourcesContent":["export var HKT;\n(function (HKT) {\n})(HKT || (HKT = {}));\n"],"mappings":";;;;;;AAAO,IAAIA,GAAJ;;;AACP,CAAC,UAAUA,GAAV,EAAe,CACf,CADD,EACGA,GAAG,mBAAKA,GAAG,GAAG,EAAX,CADN"}
|
package/_mjs/HKT.mjs
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
2
1
|
export var HKT;
|
|
3
2
|
|
|
4
|
-
(function (HKT) {
|
|
5
|
-
/*
|
|
6
|
-
* Instance util
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @tsplus macro identity
|
|
11
|
-
*/
|
|
12
|
-
function instance(_) {
|
|
13
|
-
// @ts-expect-error: typelevel utility
|
|
14
|
-
return _;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
HKT.instance = instance;
|
|
18
|
-
})(HKT || (HKT = {}));
|
|
3
|
+
(function (HKT) {})(HKT || (HKT = {}));
|
|
19
4
|
//# sourceMappingURL=HKT.mjs.map
|
package/_mjs/HKT.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HKT.mjs","names":["HKT"
|
|
1
|
+
{"version":3,"file":"HKT.mjs","names":["HKT"],"sources":["../esm/HKT.js"],"sourcesContent":["export var HKT;\n(function (HKT) {\n})(HKT || (HKT = {}));\n"],"mappings":"AAAA,OAAO,IAAIA,GAAJ;;AACP,CAAC,UAAUA,GAAV,EAAe,CACf,CADD,EACGA,GAAG,KAAKA,GAAG,GAAG,EAAX,CADN"}
|
package/_src/Check.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare namespace Check {
|
|
|
36
36
|
/**
|
|
37
37
|
* @tsplus type fncts.Check.Extends
|
|
38
38
|
*/
|
|
39
|
-
type Extends<A, B> = [A] extends [
|
|
39
|
+
type Extends<A, B> = [A] extends [B] ? unknown : never;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* @tsplus type fncts.Check.IsUnion
|
|
@@ -55,12 +55,12 @@ export declare namespace Check {
|
|
|
55
55
|
/**
|
|
56
56
|
* @tsplus type fncts.Check.IsLiteral
|
|
57
57
|
*/
|
|
58
|
-
type IsLiteral<A extends string | number> = Not<Extends<string, A> | Extends<number, A>>;
|
|
58
|
+
type IsLiteral<A extends string | number | boolean> = Not<Extends<string, A> | Extends<number, A> | Extends<boolean, A>>;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* @tsplus type fncts.Check.IsStruct
|
|
62
62
|
*/
|
|
63
|
-
type IsStruct<A> = Extends<keyof A, string> & Not<IsUnion<A>>;
|
|
63
|
+
type IsStruct<A> = Check.Extends<keyof A, string> & Check.Not<Check.IsUnion<A>>;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* @tsplus type fncts.Check.HaveSameLength
|
package/_src/HKT.ts
CHANGED
|
@@ -1,221 +1,103 @@
|
|
|
1
1
|
import type * as Union from "./Union.js";
|
|
2
2
|
|
|
3
|
-
export interface HKT {
|
|
4
|
-
readonly K?: unknown;
|
|
5
|
-
readonly Q?: unknown;
|
|
6
|
-
readonly W?: unknown;
|
|
7
|
-
readonly X?: unknown;
|
|
8
|
-
readonly I?: unknown;
|
|
9
|
-
readonly S?: unknown;
|
|
10
|
-
readonly R?: unknown;
|
|
11
|
-
readonly E?: unknown;
|
|
12
|
-
readonly A?: unknown;
|
|
13
|
-
readonly type?: unknown;
|
|
14
|
-
|
|
15
|
-
readonly index?: unknown;
|
|
16
|
-
|
|
17
|
-
readonly variance: {
|
|
18
|
-
readonly K?: HKT.Variance;
|
|
19
|
-
readonly Q?: HKT.Variance;
|
|
20
|
-
readonly W?: HKT.Variance;
|
|
21
|
-
readonly X?: HKT.Variance;
|
|
22
|
-
readonly I?: HKT.Variance;
|
|
23
|
-
readonly S?: HKT.Variance;
|
|
24
|
-
readonly R?: HKT.Variance;
|
|
25
|
-
readonly E?: HKT.Variance;
|
|
26
|
-
readonly A?: HKT.Variance;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
31
3
|
export namespace HKT {
|
|
32
|
-
declare const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export type
|
|
36
|
-
|
|
37
|
-
export type
|
|
38
|
-
|
|
39
|
-
export type
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export type
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
4
|
+
export declare const F: unique symbol;
|
|
5
|
+
export type F = typeof F;
|
|
6
|
+
export declare const K: unique symbol;
|
|
7
|
+
export type K = typeof K;
|
|
8
|
+
export declare const Q: unique symbol;
|
|
9
|
+
export type Q = typeof Q;
|
|
10
|
+
export declare const W: unique symbol;
|
|
11
|
+
export type W = typeof W;
|
|
12
|
+
export declare const X: unique symbol;
|
|
13
|
+
export type X = typeof X;
|
|
14
|
+
export declare const I: unique symbol;
|
|
15
|
+
export type I = typeof I;
|
|
16
|
+
export declare const S: unique symbol;
|
|
17
|
+
export type S = typeof S;
|
|
18
|
+
export declare const R: unique symbol;
|
|
19
|
+
export type R = typeof R;
|
|
20
|
+
export declare const E: unique symbol;
|
|
21
|
+
export type E = typeof E;
|
|
22
|
+
export declare const A: unique symbol;
|
|
23
|
+
export type A = typeof A;
|
|
24
|
+
export declare const T: unique symbol;
|
|
25
|
+
export type T = typeof T;
|
|
26
|
+
export declare const Ix: unique symbol;
|
|
27
|
+
export type Ix = typeof Ix;
|
|
28
|
+
export declare const C: unique symbol;
|
|
29
|
+
export type C = typeof C;
|
|
30
|
+
|
|
31
|
+
export type _K<X extends HKT> = X extends { [K]?: () => infer K } ? K : never;
|
|
32
|
+
export type _Q<X extends HKT> = X extends { [Q]?: (_: infer Q) => void } ? Q : never;
|
|
33
|
+
export type _W<X extends HKT> = X extends { [W]?: () => infer W } ? W : never;
|
|
34
|
+
export type _X<X extends HKT> = X extends { [X]?: () => infer X } ? X : never;
|
|
35
|
+
export type _I<X extends HKT> = X extends { [I]?: (_: infer I) => void } ? I : never;
|
|
36
|
+
export type _S<X extends HKT> = X extends { [S]?: () => infer S } ? S : never;
|
|
37
|
+
export type _R<X extends HKT> = X extends { [R]?: (_: infer R) => void } ? R : never;
|
|
38
|
+
export type _E<X extends HKT> = X extends { [E]?: () => infer E } ? E : never;
|
|
39
|
+
export type _A<X extends HKT> = [X] extends [{ [A]?: () => infer A }] ? A : never;
|
|
40
|
+
|
|
41
|
+
export type _Ix<X extends HKT> = X extends { [Ix]?: infer Ix } ? Ix : never;
|
|
42
|
+
|
|
43
|
+
export type IndexFor<X extends HKT, K> = X extends { [Ix]?: infer Ix } ? Ix : K;
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this["Q"],
|
|
80
|
-
this["W"],
|
|
81
|
-
this["X"],
|
|
82
|
-
this["I"],
|
|
83
|
-
this["S"],
|
|
84
|
-
this["R"],
|
|
85
|
-
this["E"],
|
|
86
|
-
this["A"]
|
|
87
|
-
>
|
|
88
|
-
>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface FK<F, K, Q, W, X, I, S, R, E, A> {
|
|
92
|
-
readonly _F: F;
|
|
93
|
-
readonly _K: K;
|
|
94
|
-
readonly _Q: Q;
|
|
95
|
-
readonly _W: W;
|
|
96
|
-
readonly _X: X;
|
|
97
|
-
readonly _I: I;
|
|
98
|
-
readonly _S: S;
|
|
99
|
-
readonly _R: R;
|
|
100
|
-
readonly _E: E;
|
|
101
|
-
readonly _A: A;
|
|
102
|
-
}
|
|
45
|
+
/**
|
|
46
|
+
* @tsplus type fncts.Kind
|
|
47
|
+
*/
|
|
48
|
+
export type Kind<F extends HKT, K, Q, W, X, I, S, R, E, A> = F & {
|
|
49
|
+
[F]?: F;
|
|
50
|
+
[K]?: () => K;
|
|
51
|
+
[Q]?: (_: Q) => void;
|
|
52
|
+
[W]?: () => W;
|
|
53
|
+
[X]?: () => X;
|
|
54
|
+
[I]?: (_: I) => void;
|
|
55
|
+
[S]?: () => S;
|
|
56
|
+
[R]?: (_: R) => void;
|
|
57
|
+
[E]?: () => E;
|
|
58
|
+
[A]?: () => A;
|
|
59
|
+
} extends { [T]?: infer X }
|
|
60
|
+
? X
|
|
61
|
+
: {
|
|
62
|
+
[F]?: F;
|
|
63
|
+
[K]?: () => K;
|
|
64
|
+
[Q]?: (_: Q) => void;
|
|
65
|
+
[W]?: () => W;
|
|
66
|
+
[X]?: () => X;
|
|
67
|
+
[I]?: (_: I) => void;
|
|
68
|
+
[S]?: () => S;
|
|
69
|
+
[R]?: (_: R) => void;
|
|
70
|
+
[E]?: () => E;
|
|
71
|
+
[A]?: () => A;
|
|
72
|
+
};
|
|
103
73
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
readonly _X: unknown;
|
|
110
|
-
readonly _I: unknown;
|
|
111
|
-
readonly _S: unknown;
|
|
112
|
-
readonly _R: unknown;
|
|
113
|
-
readonly _E: unknown;
|
|
114
|
-
readonly _A: A;
|
|
74
|
+
/**
|
|
75
|
+
* @tsplus type fncts.Typeclass
|
|
76
|
+
*/
|
|
77
|
+
export interface Typeclass<F extends HKT> {
|
|
78
|
+
[HKT.F]?: F;
|
|
115
79
|
}
|
|
116
80
|
|
|
117
|
-
export
|
|
118
|
-
readonly type: FK<
|
|
119
|
-
F,
|
|
120
|
-
this["K"],
|
|
121
|
-
this["Q"],
|
|
122
|
-
this["W"],
|
|
123
|
-
this["X"],
|
|
124
|
-
this["I"],
|
|
125
|
-
this["S"],
|
|
126
|
-
this["R"],
|
|
127
|
-
this["E"],
|
|
128
|
-
this["A"]
|
|
129
|
-
>;
|
|
130
|
-
readonly variance: {
|
|
131
|
-
readonly K: "_";
|
|
132
|
-
readonly Q: "_";
|
|
133
|
-
readonly W: "_";
|
|
134
|
-
readonly X: "_";
|
|
135
|
-
readonly I: "_";
|
|
136
|
-
readonly S: "_";
|
|
137
|
-
readonly R: "_";
|
|
138
|
-
readonly E: "_";
|
|
139
|
-
readonly A: "_";
|
|
140
|
-
};
|
|
141
|
-
}
|
|
81
|
+
export type ParamName = "K" | "Q" | "W" | "X" | "I" | "S" | "R" | "E" | "A";
|
|
142
82
|
|
|
143
|
-
export
|
|
144
|
-
readonly type: FK<
|
|
145
|
-
F,
|
|
146
|
-
this["K"],
|
|
147
|
-
this["Q"],
|
|
148
|
-
this["W"],
|
|
149
|
-
this["X"],
|
|
150
|
-
this["I"],
|
|
151
|
-
this["S"],
|
|
152
|
-
this["R"],
|
|
153
|
-
this["E"],
|
|
154
|
-
this["A"]
|
|
155
|
-
>;
|
|
156
|
-
readonly variance: {
|
|
157
|
-
readonly K: "_";
|
|
158
|
-
readonly Q: "_";
|
|
159
|
-
readonly W: "_";
|
|
160
|
-
readonly X: "_";
|
|
161
|
-
readonly I: "_";
|
|
162
|
-
readonly S: "_";
|
|
163
|
-
readonly R: "_";
|
|
164
|
-
readonly E: "+";
|
|
165
|
-
readonly A: "_";
|
|
166
|
-
};
|
|
167
|
-
}
|
|
83
|
+
export type Mix<N extends ParamName, P extends ReadonlyArray<unknown>> = VarianceToMix<P>[ParamToVariance[N]];
|
|
168
84
|
|
|
169
|
-
export
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this["I"],
|
|
177
|
-
this["S"],
|
|
178
|
-
this["R"],
|
|
179
|
-
this["E"],
|
|
180
|
-
this["A"]
|
|
181
|
-
>;
|
|
182
|
-
readonly variance: {
|
|
183
|
-
readonly K: "_";
|
|
184
|
-
readonly Q: "_";
|
|
185
|
-
readonly W: "_";
|
|
186
|
-
readonly X: "_";
|
|
187
|
-
readonly I: "_";
|
|
188
|
-
readonly S: "_";
|
|
189
|
-
readonly R: "-";
|
|
190
|
-
readonly E: "_";
|
|
191
|
-
readonly A: "_";
|
|
192
|
-
};
|
|
193
|
-
}
|
|
85
|
+
export type MixStruct<N extends ParamName, X, Y> = ParamToVariance[N] extends "_"
|
|
86
|
+
? X
|
|
87
|
+
: ParamToVariance[N] extends "+"
|
|
88
|
+
? Y[keyof Y]
|
|
89
|
+
: ParamToVariance[N] extends "-"
|
|
90
|
+
? Union.IntersectionOf<{ [K in keyof Y]: OrNever<Y[K]> }[keyof Y]>
|
|
91
|
+
: X;
|
|
194
92
|
|
|
195
|
-
export type
|
|
93
|
+
export type Intro<N extends ParamName, A, B> = VarianceToIntro<A, B>[ParamToVariance[N]];
|
|
196
94
|
|
|
197
|
-
export type
|
|
198
|
-
readonly type: unknown;
|
|
199
|
-
}
|
|
200
|
-
? (F & {
|
|
201
|
-
readonly K: OrFix<C, "K", K>;
|
|
202
|
-
readonly Q: OrFix<C, "Q", Q>;
|
|
203
|
-
readonly W: OrFix<C, "W", W>;
|
|
204
|
-
readonly X: OrFix<C, "X", X>;
|
|
205
|
-
readonly I: OrFix<C, "I", I>;
|
|
206
|
-
readonly S: OrFix<C, "S", S>;
|
|
207
|
-
readonly R: OrFix<C, "R", R>;
|
|
208
|
-
readonly E: OrFix<C, "E", E>;
|
|
209
|
-
readonly A: A;
|
|
210
|
-
})["type"]
|
|
211
|
-
: FK<F, K, Q, W, X, I, S, R, E, A>;
|
|
95
|
+
export type Low<N extends ParamName> = VarianceToLow[ParamToVariance[N]];
|
|
212
96
|
|
|
213
|
-
export type Infer<F extends HKT,
|
|
214
|
-
Kind<F,
|
|
97
|
+
export type Infer<F extends HKT, N extends ParamName, K> = [K] extends [
|
|
98
|
+
Kind<F, infer K, infer Q, infer W, infer X, infer I, infer S, infer R, infer E, infer A>,
|
|
215
99
|
]
|
|
216
|
-
? N extends "
|
|
217
|
-
? C
|
|
218
|
-
: N extends "K"
|
|
100
|
+
? N extends "K"
|
|
219
101
|
? K
|
|
220
102
|
: N extends "Q"
|
|
221
103
|
? Q
|
|
@@ -236,114 +118,64 @@ export namespace HKT {
|
|
|
236
118
|
: never
|
|
237
119
|
: never;
|
|
238
120
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
*/
|
|
242
|
-
|
|
243
|
-
export interface Lows {
|
|
244
|
-
"-": unknown;
|
|
245
|
-
"+": never;
|
|
246
|
-
_: any;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export type Low<F extends HKT, N extends ParamName> = F["variance"][N] extends Variance
|
|
250
|
-
? Lows[F["variance"][N]]
|
|
251
|
-
: never;
|
|
252
|
-
|
|
253
|
-
/*
|
|
254
|
-
* Type mixing for variance
|
|
255
|
-
*/
|
|
256
|
-
|
|
257
|
-
export interface Mixes<P extends ReadonlyArray<unknown>> {
|
|
258
|
-
"-": P extends [any]
|
|
259
|
-
? P[0]
|
|
260
|
-
: P extends [any, any]
|
|
261
|
-
? P[0] & P[1]
|
|
262
|
-
: P extends [any, any, any]
|
|
263
|
-
? P[0] & P[1] & P[2]
|
|
264
|
-
: P extends [any, any, any, any]
|
|
265
|
-
? P[0] & P[1] & P[2] & P[3]
|
|
266
|
-
: P extends [any, any, any, any, any]
|
|
267
|
-
? P[0] & P[1] & P[2] & P[3] & P[4]
|
|
268
|
-
: Union.IntersectionOf<P[number]>;
|
|
269
|
-
"+": P[number];
|
|
270
|
-
_: P[0];
|
|
271
|
-
}
|
|
272
|
-
export type Mix<
|
|
273
|
-
F extends HKT,
|
|
274
|
-
N extends ParamName,
|
|
275
|
-
P extends ReadonlyArray<unknown>,
|
|
276
|
-
> = F["variance"][N] extends Variance ? Mixes<P>[F["variance"][N]] : P[0];
|
|
277
|
-
|
|
278
|
-
export type OrNever<K> = unknown extends K ? never : K;
|
|
279
|
-
|
|
280
|
-
export type MixStruct<F extends HKT, N extends ParamName, X, Y> = F["variance"][N] extends "_"
|
|
281
|
-
? X
|
|
282
|
-
: F["variance"][N] extends "+"
|
|
283
|
-
? Y[keyof Y]
|
|
284
|
-
: F["variance"][N] extends "-"
|
|
285
|
-
? Union.IntersectionOf<{ [k in keyof Y]: OrNever<Y[k]> }[keyof Y]>
|
|
286
|
-
: X;
|
|
287
|
-
|
|
288
|
-
export interface Intros<A, B> {
|
|
289
|
-
"-": B;
|
|
290
|
-
"+": B;
|
|
291
|
-
_: A;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/*
|
|
295
|
-
* Type introduction for variance
|
|
296
|
-
*/
|
|
297
|
-
|
|
298
|
-
export type Intro<F extends HKT, N extends ParamName, A, B> = F["variance"][N] extends Variance
|
|
299
|
-
? Intros<A, B>[F["variance"][N]]
|
|
300
|
-
: A;
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Type parameter constraint
|
|
304
|
-
*/
|
|
305
|
-
|
|
306
|
-
export type None = {};
|
|
307
|
-
|
|
308
|
-
declare const Fix: unique symbol;
|
|
309
|
-
|
|
310
|
-
export interface Fix<N extends ParamName, A> {
|
|
311
|
-
[Fix]: {
|
|
312
|
-
[K in N]: () => A;
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
declare const Extend: unique symbol;
|
|
121
|
+
export type ErasedKind<F extends HKT> = HKT.Kind<F, any, any, any, any, any, any, any, any, any>;
|
|
122
|
+
}
|
|
317
123
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
124
|
+
export interface HKT {
|
|
125
|
+
[HKT.F]?: HKT;
|
|
126
|
+
[HKT.K]?: () => unknown;
|
|
127
|
+
[HKT.Q]?: (_: never) => void;
|
|
128
|
+
[HKT.W]?: () => unknown;
|
|
129
|
+
[HKT.X]?: () => unknown;
|
|
130
|
+
[HKT.I]?: (_: never) => void;
|
|
131
|
+
[HKT.S]?: () => unknown;
|
|
132
|
+
[HKT.R]?: (_: never) => void;
|
|
133
|
+
[HKT.E]?: () => unknown;
|
|
134
|
+
[HKT.A]?: () => unknown;
|
|
135
|
+
[HKT.T]?: unknown;
|
|
136
|
+
[HKT.Ix]?: unknown;
|
|
137
|
+
}
|
|
323
138
|
|
|
324
|
-
|
|
139
|
+
interface VarianceToMix<P extends ReadonlyArray<unknown>> {
|
|
140
|
+
"-": P extends [any]
|
|
141
|
+
? P[0]
|
|
142
|
+
: P extends [any, any]
|
|
143
|
+
? P[0] & P[1]
|
|
144
|
+
: P extends [any, any, any]
|
|
145
|
+
? P[0] & P[1] & P[2]
|
|
146
|
+
: P extends [any, any, any, any]
|
|
147
|
+
? P[0] & P[1] & P[2] & P[3]
|
|
148
|
+
: P extends [any, any, any, any, any]
|
|
149
|
+
? P[0] & P[1] & P[2] & P[3] & P[4]
|
|
150
|
+
: Union.IntersectionOf<P[number]>;
|
|
151
|
+
"+": P[number];
|
|
152
|
+
_: P[0];
|
|
153
|
+
}
|
|
325
154
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
155
|
+
interface VarianceToIntro<A, B> {
|
|
156
|
+
"-": B;
|
|
157
|
+
"+": B;
|
|
158
|
+
_: A;
|
|
159
|
+
}
|
|
331
160
|
|
|
332
|
-
|
|
161
|
+
interface VarianceToLow {
|
|
162
|
+
"-": unknown;
|
|
163
|
+
"+": never;
|
|
164
|
+
_: any;
|
|
165
|
+
}
|
|
333
166
|
|
|
334
|
-
|
|
167
|
+
interface ParamToVariance {
|
|
168
|
+
K: "_";
|
|
169
|
+
Q: "-";
|
|
170
|
+
W: "+";
|
|
171
|
+
X: "+";
|
|
172
|
+
I: "_";
|
|
173
|
+
S: "_";
|
|
174
|
+
R: "-";
|
|
175
|
+
E: "+";
|
|
176
|
+
A: "+";
|
|
177
|
+
}
|
|
335
178
|
|
|
336
|
-
|
|
337
|
-
* Instance util
|
|
338
|
-
*/
|
|
179
|
+
type OrNever<K> = unknown extends K ? never : K;
|
|
339
180
|
|
|
340
|
-
|
|
341
|
-
* @tsplus macro identity
|
|
342
|
-
*/
|
|
343
|
-
export function instance<F>(
|
|
344
|
-
_: Omit<F, typeof URI | typeof CURI | "_F" | "_G" | "_CF" | "_CG">,
|
|
345
|
-
): F {
|
|
346
|
-
// @ts-expect-error: typelevel utility
|
|
347
|
-
return _;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
181
|
+
declare const Fix: unique symbol;
|